emmmmmmmmmmmmmmmmmm,鍊錶操作好煩呀,說白了,其實是指標煩。其實我還是未能很理解,指標誰指誰,只能多擼幾次**來增加理解。
#include #include typedef int elementtype;
typedef struct _node node;
/**< 其實還是未能很好理解再建立乙個list結構,老師說是為了日後可以加入node *tail等操作而準備的;
我現在暫時未能看出門道,只能依葫蘆畫瓢 */
typedef struct _list
list;
void addlist(list *plist, elementtype x);
void displaylist(list *plist);
int lengthoflist(list *plist);
node *findkth(list *plist, int k);
int finddata(list *plist, elementtype x);
void insertdata(list *plist, elementtype x, int i);
void deletedata(list *plist, int i);
int lengthoflist(list *plist)
return cnt;
}void displaylist(list *plist)
printf("\n");
}node *findkth(list *plist, int k)
if( i==k )
else
}int finddata(list *plist, elementtype x)
return -1;
}void addlist(list *plist, elementtype x)
last->next = tmp;
}else
}void insertdata(list *plist, elementtype x, int i)
else
else
}}void deletedata(list *plist, int i)
else
else
}}int main()
displaylist(&phead);
printf("\nlength of the list: %d\n", lengthoflist(&phead));
pub = findkth( &phead, 2);
printf("2nd data: %d\n", pub->data);
printf("data 3 is in position: %d\n", finddata(&phead, 3));
insertdata(&phead, 10, 1);
displaylist(&phead);
printf("delete test3\n");
deletedata(&phead, 3);
displaylist(&phead);
printf("delete test1\n");
deletedata(&phead, 1);
displaylist(&phead);
system("pause");
}
鍊錶插入刪除操作
include using namespace std 定義單向鍊錶節點 struct listnode end of listnode 將新節點插入煉表頭 void insertlist listnode head,int insertdata listnode pnode new listnod...
鍊錶 建立 插入 刪除 查詢
include include typedef struct node int data struct node next node node createlist 建立乙個單鏈表 printf 建立乙個長度為 n的鍊錶,請輸入 n int n scanf d n node l l node mal...
雙向鍊錶插入 刪除操作
雙向鍊錶 迴圈單鏈表的出現,雖然能夠實現從任一結點出發沿著鏈能找到其前驅結點,但時間耗費是o n 如果希望從表中快速確定某乙個結點的前驅,另乙個解決方法就是在單鏈表的每個結點裡再增加乙個指向其前驅的指標域prior。這樣形成的鍊錶中就有兩條方向不同的鏈,我們可稱之為雙 向 鍊錶 doublelink...