1. 程式人生 > >使帶頭節點的單鏈表元素遞增有序

使帶頭節點的單鏈表元素遞增有序

#include "stdafx.h"
#include<stdio.h> 
#include<malloc.h> 
#include<stdlib.h>
typedef int type;
typedef struct lnode //定義連結串列結點的資料結構 
{
    int data;
    struct lnode *next;
}Lnode;
typedef Lnode node;
typedef struct dnode//定義雙鏈表結點的資料結構 
{
    int data;
    struct dnode *lnext;
    struct dnode *rnext;
}Dnode;
void bubblesort6(node *h)//氣泡排序交換結點值
{
    int w, i, change, j;
    node *tem;
    for (i = getlength(h), change = 1; i>1 && change; i--)
    {
        change = 0;
        for (j = 1; j<i; ++j)
        if (get(h, j)->data>get(h, j + 1)->data)
        {
            w = get(h, j)->data;
            get(h, j)->data = get(h, j + 1)->data;
            get(h, j + 1)->data = w;
            change = 1;
        }
    }

}