單鏈表的簡單實現

2021-08-14 20:16:40 字數 1555 閱讀 8050

關於單鏈表的操作中,關係到頭節點建立和更改的要用二級指標或者一級指標引用,其他的可用一級指標
#pragma once

#include#includeusing namespace std;

typedef struct listnode

node;

void printlist(node* head);

node* buynode(int x);//創造新節點

void pushback(node* &head,int x);

void pushfront(node* &head,int x);

void popback(node* &head);

void popfront(node* &head);

node* find(node* head,int x);

void destory(node* &head);//清空鍊錶

void insert(node* &head, node* pos, int x);

void erase(node* &head, node* pos);

//輸出鍊錶

void printlist(node* head)

cout << "null" << endl;

}//創造新節點

node* buynode(int x)

//尾插

void pushback(node* &head, int x)

else

cur->next = buynode(x); }}

//頭插

void pushfront(node* &head, int x)

}//尾刪

void popback(node* &head)

else

free(cur->next);

cur->next = null; }}

//頭刪

void popfront(node* &head)

else }

node* find(node* head,int x)

return null;

}//清空鍊錶

void destory(node* &head)

head = null;

}//在pos前面插入元素x

void insert(node* &head, node* pos, int x)

node* newnode = buynode(x);

newnode->next = cur->next;

cur->next = newnode; }}

//指定位置刪除

單鏈表簡單實現

單鏈表的形式 頭部有個head節點每個節點都向後關聯乙個節點 下面是我的單鏈表的插刪改查和反轉的操作 include include include typedef struct node list define node size sizeof struct node typedef struct...

單鏈表的簡單實現

include include include define max list length 20 define expand list length 5 using namespace std include include typedef struct node node,list 初始化乙個l...

單鏈表的簡單實現

單鏈表 鍊錶是一種鏈式訪問的資料結構,用一組位址任意的儲存單元存放線性表中的資料元素。鍊錶中的資料是以結點來表示的,每個結點的構成 元素 資料元素的映象 指標 指示後繼元素儲存位置 標頭檔案.結構的定義和 簡單函式實現的宣告 pragma once include include include t...