鍊錶 的增刪改查

2021-10-06 12:38:23 字數 4154 閱讀 8569

#include

#include

#include

typedef struct student

student;

student *createlist(student *stu , int num )

qnew->num = stu[num - flag - 1].num ;

qnew->next = null ;

if(null == head)

else

}printf("建立完成!\n") ;

}else

return head ;

}int getlistlength(student *head)

}printf("鍊錶長度為%d\n",index) ;

return index ;

}student * searchlistindex(student *head , int index)

if(index <= 0||index >getlistlength(head) )

while(--index)

return head ;

}/****/

void showlist(student *head)

else

putchar(10) ;

}//釋放鍊錶

void freelist(student *head)

}printf("釋放完成!\n") ;

}student * insertlist(student *head,int data , int index)

student *pnew = (student*)malloc(sizeof(student)) ;

assert(pnew!=null) ;

pnew -> num = data ;

pnew ->next = null ;

if(1 == index)

else 

return head ;

}student * deletelist(student *head , int index)

int len = getlistlength(head) ; 

if(index < 1 || index > len)

if(1 == index)

else

return head ;

}int main()

head = createlist(stu , 9) ;

showlist(head) ;

student *pindex = searchlistindex(head , 3) ;

if(null == pindex)

else

deletelist(head ,9) ;

showlist(head) ;

student *pinsert = insertlist(head , 12,9) ;

showlist(pinsert) ;

freelist(head) ;

printf("hello  link\n");

return 0 ;

}

#include "./dnode.h"

#include

#include

dnode * createdoublelink()

else

}return head ;

} int getlinklen(dnode * head)

return len ;

}void showlink(dnode *head)

printf("鍊錶資料為:\n") ;

while(head)

putchar(10) ;

dnode * getnodeatindex(dnode * head , int index) 

return head ;

}dnode * insertlink(dnode * head , int data , int index) 

dnode *pretemp = null;

dnode *pnew = (dnode*)malloc(sizeof(dnode)) ;

pnew -> pre = null ;

pnew -> next = null ; 

pnew -> data = data ;

if(1 == index)

//2,非空鍊錶,頭插入

else

}else if(index > 1 && index < len ) //中間插入

else if(index == len)    //尾插入

return head ;

}dnode * findmax(dnode *head) }} 

//排序

dnode * sortlink(dnode * head) 

dnode *p =null ;

dnode *q =null ;

while(null != head)

else

}return q ;

}

#include

#include

#define len 11

void inithash(int hash)

int hashinsert(int hash ,int data)

else

node ;

void hashlinkinit(node *hash)

int hashlinkinsert(node * hash ,int data)

else

p->next = pnew ;

return 0 ;

}return -1;

}void showhashlink(node *hash)}}

}int main()

#include

#include

#include

typedef struct btree

btree ;

btree *createbtree()

else

else

}    

if( q -> data > data)

else

}printf("請輸入下一節點的資料\n") ;

scanf("%d",&data) ;

while(getchar()!='\n') ;

}return root ;

}//先序遞迴遍歷

void showdiguipre(btree * root)

}//先序非遞迴遍歷

void showorderbypre(btree *root)

btree *stack[100] ;

int top = -1 ;

btree * p;

stack[++top] = root ;

while(top != -1)

}//中序非遞迴遍歷

void showorderbyinter(btree * root)

btree * stack [100] ;

int top = -1 ;

btree * p = root ;

while(-1 != top || null != p)

if(-1 != top )}}

//後序非遞迴遍歷

void showorderbypost(btree * root)

while(-1 != top2)

}//遞迴中序

void showdiguiinter(btree * root)

}//遞迴後序

void showdiguipost(btree * root)}/*

//層次遍歷

void showlevel(btree *root)

btree *que[100] ;

int front ,rear ;

front = rear = 0;

btree *q = null ;

rear = (rear+1)%100 ;}*/

int main()

mysql增刪改查鍊錶 鍊錶的增刪改查

include include 先定義鍊錶裡面的元素。typedef struct nodemynode 定義整個鍊錶。typedef struct linkmylink int isempty to mylink mylink mylink 判斷鍊錶是否為空。int push to mylinki...

鍊錶 增刪改查

實現 鍊錶的增刪改查 package com.baicai.linkedlist public class singlinkedlistdome 定義乙個singlinkedlist管理我們的英雄 class singlelinkedlist 如果沒有找到最後的乙個節點就直接往後面找 temp te...

鍊錶的增刪改查

include include define true 1 define false 0 int s 0 定義全域性變數s接收查詢資料的位置 結點型別定義 typedef struct linknode node 構造鍊錶 帶頭結點的尾插法建表 node create list tail next ...