#include
#include
#define error 0
#define ok 1
typedef int elemtype; //建立帶表頭結點的單鏈表
typedef struct node
node;
typedef struct
headerlist;
typedef int status;
status init (headerlist *h ) //對單鏈表初始化
status insert(headerlist *h,int i,elemtype x)//單鏈表的插入操作
status output(headerlist h)//單鏈表的輸出操作
return ok;
}void invert(headerlist *h) //實現單鏈表的逆置
}void main()
{int i;
int x;
headerlist list;
init (&list); //單鏈表初始化
for(i=0;i<9;i++)
insert (&list,i-1,i); //插入資料
printf("the linklist is:");
output(list);
invert(&list); //執行逆置操作
printf("\nthe linklist is:");
output(list);
結果不太完整,後面出現-842150451是位置因為帶表頭單鏈表最前面有乙個空白鏈,但執行的過程中有乙個問題,最後乙個鍊錶8的位置後面沒有後續結點,所以最後乙個結點沒有逆置
C語言 單鏈表實現(二) 就地逆置,就地歸併
include include include define len sizeof struct nodelist using namespace std typedef struct nodelist nodelist 函式宣告 void error char s 錯誤處理函式 nodelist ...
單鏈表(頭插法)c語言實現
鍊錶 結構體變數與結構體變數聯絡在一起 動態建立鍊錶 動態記憶體申請 模組化設計 1.建立鍊錶 建立乙個表頭表示整個鍊錶 2.建立節點 3.插入節點 4.刪除節點 5.列印,遍歷鍊錶 可以用來做測試 include include struct listnode 建立鍊錶 struct listno...
C語言實現單鏈表的逆置
單鏈表的逆置是乙個非常經典的問題,這裡利用兩個思想進行解決。首先,我們需要看下原理圖,其實兩個思想都是一樣的,都是使後乙個的節點的 next 指標指向前乙個節點,依次遞推,直到第二個節點指向第乙個節點,第乙個節點的 next 指標指向 null。第一種方法 在鍊錶往前走的過程中,記錄前乙個節點,當前...