日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

自己写的单链表

發(fā)布時(shí)間:2023/11/27 生活经验 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 自己写的单链表 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
link.c
#include <stdio.h>
#include <malloc.h>
#include <string.h> 
#include <stdlib.h>
#include? "link.h"/****? 這是一個(gè)計(jì)算HASH值的算法**/
int time33(char* arKey,int arlength){int h = 0;int i;for(i=0;i<arlength;i++){h = h*33 + (int)*arKey++;}return h;?? ?
}//創(chuàng)建節(jié)點(diǎn)
struct node* createNode(char* key,char* s)
{int node_key=0;//強(qiáng)制轉(zhuǎn)換,假如使用(void* value)//char* arKey = (char*)key;int len =strlen(key);struct node* new_node=(struct node*)malloc(sizeof(struct node));if(new_node==NULL){printf("內(nèi)存分配失敗\n");}memset(new_node,0,sizeof(new_node));node_key = time33(key,len);new_node->value=node_key;new_node->string=s;new_node->next=NULL;return new_node;
}//新增節(jié)點(diǎn)
void add(struct node* head,char* key,char* s)
{struct node* new_node=createNode(key,s);while(head->next!=NULL){head=head->next;}head->next=new_node;
}//搜索節(jié)點(diǎn)
char* searchNode(struct node* head,char* key)
{int len = strlen(key);int node_key = time33(key,len);while(head->next!=NULL){if(head->value==node_key){return head->string;}head=head->next;}return NULL;
}//刪除節(jié)點(diǎn)
int deleteNode(struct node* head,char* key)
{int i=0;int len = strlen(key);int node_key = time33(key,len);while(head->next->next!=NULL){if(head->next->value==node_key){struct node* d_node=head->next;head->next=head->next->next;free(d_node);return i;}i++;head=head->next;}return 0;
}//主文件
int main()
{int d1=0;char* s1;struct node* head=createNode("0","0");add(head,"aa","aaa");add(head,"bb","bbb");add(head,"cc","ccc");add(head,"dd","ddd");add(head,"ee","eee");add(head,"ff","fff");s1=searchNode(head,"cc");d1=deleteNode(head,"bb");return 0;
}
link.h
#define HASHSIZE 13
struct node{
int value;
char* string;
struct node* next;
};


總結(jié)

以上是生活随笔為你收集整理的自己写的单链表的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。