鍊錶的簡單操作

2021-07-31 11:07:28 字數 1130 閱讀 3906

鍊錶的簡單操作大致包括:頭插法尾插法建立鍊錶,遍歷鍊錶,刪除新增結點。

#include

#include

typedef struct node

node;

void print(node *head) .//遍歷鍊錶

printf("\n");

return ;

}node *create_linklist(int n) //頭插法建立鍊錶

}return head;

}/*node

*create_linklist(int n) //建立鍊錶 ,尾插法

return head;

}*/node *insert_node(node *head,int b) //插入大小為b的結點

else

if(p->data < head->data)

else

p->next = pre1;

pre2->next = p;

}return head;

}node *delete_node(node *head ,int b) //刪除元素為b的結點

if(b == p->data)

else

printf("%d not found,delete fail.\n",b);

}return head;

}node *delete_n_node(node *head,int n) //刪除第n個結點

else

if(p ->next == null)

printf("there is less than %d.\n",n);

else

pre->next = p->next;

free(p);

}return head;

}node *insert_n_node(node *head, int n) //在第n個結點後面插入乙個結點

else

if(i == n)

else

printf("null\n");

}return head;

}int main()

鍊錶的簡單操作

鍊錶程式設計 一 實驗目的 1 掌握建立鍊錶中指標的運用 插入刪除節點的方法 二 實驗準備 1 複習鍊錶的概念 建立鍊錶的過程 鍊錶節點的插入與刪除 2 預習實驗內容,並在預習報告上寫出程式流程圖 或源 3 上機輸入源程式,除錯執行並記錄執行結果 4 將源程式存在自己的u盤上,課後按要求寫實驗報告。...

簡單鍊錶操作

先是最簡單的,建立,刪除節點,有序鍊錶新增節點,反轉等,如下 include using namespace std struct node node createlink int a,int len else return head void show node head coutelse bre...

簡單鍊錶操作

include using namespace std 鍊錶結構體 struct node 建立鍊錶 返回煉表頭指標 node createnodes head head next next next null return head 列印鍊錶,未使用遞迴 void printnodes node ...