C语言数据结构-线性表-单链表
来源:互联网 发布:双鱼玉佩 知乎 编辑:程序博客网 时间:2024/06/05 17:17
#include<stdio.h>#include<stdlib.h>typedef struct LNode{ int num; struct LNode *next;}LNode, *LNodeList;LNodeList init(){ LNodeList lList=(LNodeList)malloc(sizeof(struct LNode)); lList->num=0; lList->next=NULL; return lList;}void add(int num,LNodeList lList){ LNodeList nList=(LNodeList)malloc(sizeof(struct LNode)); nList->next=NULL; nList->num=num; LNodeList current=lList; while(current->next!=NULL){ current=current->next; } current->next=nList;}void insert(int num,int index,LNodeList lList){ int i=0; LNodeList newNode=(LNodeList)malloc(sizeof(struct LNode)); newNode->num=num; LNodeList current=lList; while(current->next!=NULL){ if(i==index){ newNode->next=current->next; current->next=newNode; break; } current=current->next; i++; }}void delete(int index,LNodeList lList){ int i=0; LNodeList current=lList->next; LNodeList pre=lList; while(current!=NULL){ if(i==index){ pre->next=current->next; free(current); break; } pre=current; current=current->next; i++; }}int query(int num,LNodeList lList){ LNodeList current=lList->next; int i=0; while(current!=NULL){ if(current->num==num){ return i; } current=current->next; i++; } return -1;}void printAll(LNodeList lList){ LNodeList current=lList->next; while(current!=NULL){ printf("node=%d->",current->num); current=current->next; }}/*** 带有头结点的单链表实现线性表操作*/int main(){ LNodeList list=init(); add(5,list); add(6,list); add(8,list); insert(4,0,list); insert(7,3,list); delete(0,list); delete(2,list); int index=query(8,list); printf("index=%d",index); printAll(list); return 1;}
阅读全文
1 0
- C语言数据结构-线性表-单链表
- 数据结构(C语言)线性表 -单链表
- 数据结构(C语言) 线性表 链式存储 单链表
- 线性表数据结构C语言实现
- C语言数据结构--(线性表一)
- C语言数据结构之线性表
- C语言数据结构之线性表
- C语言数据结构之线性表(续)
- 数据结构_1:线性表: C语言实现
- 数据结构_1:线性表: C语言练习题
- 【数据结构】C语言线性表操作
- 【C语言 数据结构】 简单线性表实现
- C语言实现数据结构--线性表
- C语言数据结构-线性表-数组
- C语言数据结构-线性表-双链表实现
- C语言数据结构——线性表
- C语言 数据结构 线性表 单链表 线性表的链式存储结构之一
- 【数据结构】数据结构C语言的实现(线性表)
- 发布出 SignTool 报告了一个错误“未能给 bin\Debug\LTCY_Client.publish\\setup.exe 签名 是怎么回事
- 单例模式
- POJ3686 The Windy's
- 第三章:3.4 处理登陆的请求
- sublime text 3中文乱码问题解决办法
- C语言数据结构-线性表-单链表
- 约瑟夫问题的解决(有n个人围成一圈,顺序排号,从第一个开始报数(从1到3报数),凡报到3的人退出圈子,问最后最后留下的是原来第几号的那位.)
- 可持久化trie
- NOI2016区间
- 127.0.0.1与localhost不同源
- asp.net mvc 获取微信公众号用户输入的消息
- ARM学习笔记,技术更新
- 第三章:3.5 将登陆成功以后的页面 通过 HTML来代替,使用 htpresponsredirect 重定向
- 数据库存中文变成问号