鍊錶的簡單操作 建立,輸出,插入,刪除

2021-06-23 02:08:16 字數 765 閱讀 5698

#include #include #define len sizeof(struct student)

int n=0; //節點數量

struct student

*head;

struct student *creat(void)

p2->next=null;

return head;

} void add(int n) //插入到節點n, 是在n之前乙個,還是n之後乙個?

q->next = p; //將要插入結點位置前面的結點指標域指向現在插入的結點首位址

n++; //節點數加1

}void del(int t)

while( inext;free(q);} //表頭

else if(t==n) q->next=null; //表尾

else //表中

*/pre->next=q->next;

free(q);

n--; //節點數加1

}void print(struct student *p)

while(p != null );

}void main()

else

/* printf("continue?y/n:");

scanf("%c",c);

if(c=='y'||c=='y') flag=1;

else flag=0;

} */

}

鍊錶的基礎操作建立插入刪除輸出

include using namespace std node creat int n 建立有個n個結點的單鏈表 node insert node h,int m,int l 在單鏈表的第幾個元素之後插入值l node remove node h,int t,int n 刪除鍊錶中值為t的元素 v...

鍊錶的建立,插入,刪除,輸出基本操作

include include struct student 定義乙個學生結點,結點包括值域和指標域 typedef struct student list list createlist list insertnode list h,list s list deletenode list h,lo...

完整的鍊錶操作(定義 建立 插入 刪除 輸出)

include include struct student int icount 全域性變數表示鍊錶長度 struct student create else pnew struct student malloc sizeof struct student 再次分配結點記憶體空間 scanf s ...