C 關於鍊錶的增刪查改

2021-10-10 14:22:35 字數 1056 閱讀 7098

#include

using namespace std;

struct  listnode;

void printlist(listnode *head,int n)

cout<>n;

listnode* head = new listnode;

listnode *temp = new listnode;

temp = head;

cout<<"請輸入鍊錶資料:"<>p->data;

temp->next = p;

temp = p;

}temp->next = null;

cout<<"已生成鍊錶"<>newdata>>position;

newnode->data = newdata;

temp = head;

for(int i=0;inext; 

}cout<<"已在第"next;

temp->next = newnode;

printlist(head,n+1);  

//刪除指定節點

int deletenode;

cout<<"請輸入您想刪除的節點位置:"<>deletenode;

temp = head;

for(int i=1;inext;

}listnode *t =temp->next;

temp->next = t->next;

cout<<"已刪除第"<>changedata>>changeposition;

temp=head->next;

for(int i=1;inext;

}cout<<"已將"printlist(head,n);

//查詢指定值;

int searchdata;

cout<<"請輸入您想查詢的值:"<>searchdata;

temp=head->next;

for(int i=0;idata == searchdata)

cout<<"抱歉,未在鍊錶找到"<

鍊錶的增刪查改

include include typedef struct student stu,pstu void list head insert pstu pphead,stu pptail,int i 鍊錶為空,頭尾指標都指向新節點 else 新節點 pnext指向原本頭節點,新節點作為頭節點 void...

鍊錶 增 刪 查 改 排序

define crt secure no warnings include include include typedef struct num ss ss head null int count 0 void add node void remove node int id void seek n...

鍊錶基礎(增刪查改)

靜態鍊錶的應用範圍只限於本函式,有侷限性,無法跨函式呼叫,所以在子函式中要malloc分配記憶體。鍊錶的資料型別是結構體。define crt secure no warnings include stdio.h include stdlib.h include string.h typedef s...