C語言實現雙向鍊錶,增刪改查,排序

2021-08-04 17:36:26 字數 2424 閱讀 5825

#include#includetypedef struct node* nodeptr;

typedef struct node

node;

void putprev(int data, nodeptr head)

node->data = data;

node->next = null;

node->prev = null;

nodeptr p = head;

while (p->prev!=null)

node->next = p;

p->prev = node;

}void putnext(int data, nodeptr head)

node->data = data;

node->next = null;

node->prev = null;

nodeptr p = head;

while (p->next != null)

node->prev = p;

p->next = node;

}//插入並排序

void putbysort(int data, nodeptr head)

node->data = data;

node->next = null;

node->prev = null;

nodeptr p = head;

if (data>p->data)

if (p == null)

else

}else

if (p == null)

else }}

//氣泡排序

void sort(nodeptr head)

if (pnext->next ==null && p->data > pnext->data)//只有兩個引數

nodeptr q;

int tmp;

for (; p->next!=null; p=p->next)

} }}

//查nodeptr getnode(int position, nodeptr head)

} return p;

}//增

void insertnode(int data, int position,nodeptr head)

//刪除節點

void deletenode(int position, nodeptr head)

//改void modifynode(int data,int position, nodeptr head)

//列印鍊錶

void printnode(nodeptr list)

nodeptr node = nodeprev;

while (node != null) }

printf("\n");

}void main() ;

int length = sizeof(intarr) / sizeof(intarr[0]);

//插入的時候排序

/*for (i = 0; i < length; i++)

*/ //插入資料

for (i = 0; i < length; i++)

//首次插入資料後

printf("首次插入資料後:\n");

printnode(list);

//增int position = 5;

int addnum = 6;

insertnode(addnum, position, list);

//新增數字後

printf("在第%d位插入資料%d後:\n",position,addnum);

printnode(list);

//刪position = 10;

deletenode(position, list);

printf("刪除第%d位資料後:\n", position);

printnode(list);

//改position = 4;

int modifynum = 12;

modifynode(modifynum, position, list);

printf("將第%d位資料改為%d後:\n", position,modifynum);

printnode(list);

//查position = 9;

nodeptr p = getnode(position,list);

printf("第%d位資料為%d。\n", position, p->data);

//氣泡排序

sort(list);

printf("氣泡排序後:\n");

printnode(list);

system("pause");

}

C語言 雙向鍊錶的增刪改查

主題 雙向鍊錶 功能 分別實煉表的插入 刪除 查詢操作 define crt secure no warnings include include typedef struct student stu,pstu 列印 void list print pstu phead,pstu ptail pri...

資料結構雙向鍊錶的增刪改查(c語言實現)

帶頭 雙向 迴圈鍊錶增刪查改實現 typedef int ltdatatype typedef struct listnode listnode 1 建立返回鍊錶的頭結點 listnode listcreate 2 雙向鍊錶銷毀 雙向鍊錶銷毀 void listdestory listnode ph...

雙向鍊錶的增刪改查

package com.mjw.linkedlist 1.遍歷 和單鏈表的思路一致 2.新增 先找到雙向鍊錶的最後 temp.next new heronode newheronode.pre temp 3.修改也是和單鏈表的思路一致 4.刪除 因為是雙向鍊錶,可以自我刪除,直接找到要刪除的結點,比...