循环单链表学习
来源:互联网 发布:mac unable to launch 编辑:程序博客网 时间:2024/05/21 07:16
#include<stdio.h>#include<stdlib.h>typedef int ElemType;typedef struct CLNode{struct CLNode *next;ElemType data;}CLNode,*LinkList;//初始化循环单链表int Init_List(LinkList &L){L=(LinkList)malloc(sizeof(CLNode));L->next=L;return 0;}//插入元素int Insert_List(LinkList &L,int pos,ElemType e){int j=0;LinkList p=L->next,s;while(j<pos-1){p=p->next;j++;} s=(LinkList)malloc(sizeof(CLNode)); s->data=e; s->next=p->next; p->next=s; if(p==L) L=s;return 0;}//删除元素int Delete_List(LinkList &L,int pos,ElemType &e){int j=0;LinkList p=L->next,q;while(j<pos-1){ p=p->next; j++;}q=p->next;e=q->data;p->next=q->next;if(q->next==L->next)L=p;free(q);return 0;}//得到元素int Get_List(LinkList L,int pos ,ElemType &e){int j=0;LinkList p=L->next;while(j<pos-1){p=p->next;j++;}e=p->next->data; return e;}//清空循环链表int Clear_List(LinkList &L){LinkList p,q;L=L->next;p=L->next;while(p!=L){ q=p->next; free(p); p=q;}L->next=L;return 0;}//判空循环链表int Empty_List(LinkList L){if(L->next==L)return 1;elsereturn 0;}
//主函数int main(){LinkList L,k;int j;int e;Init_List(L);for(j=1;j<=5;j++){Insert_List(L,1,j);}for(k=L->next->next;k!=L->next;k=k->next){ printf("%d ",k->data);}printf("\n");Delete_List(L,5,e);printf("%d ",e);printf("\n");for(k=L->next->next;k!=L->next;k=k->next){ printf("%d ",k->data);}printf("\n");Get_List(L,3,e);printf("%d",e);printf("\n");Clear_List(L);printf("%d\n",Empty_List(L)); return 0;}
0 0
- 循环单链表学习
- 学习循环
- 学习循环
- oracle学习--循环语句
- [C学习]循环控制
- oracle学习--循环语句
- oracle学习--循环语句
- oracle学习--循环语句
- 汇编学习--7.10--循环
- Oracle 循环学习
- 循环学习小笔记
- python学习-循环线程
- PHP学习 - 循环任务
- while 循环的学习
- JavaScript学习(5.4):循环
- CasperJS学习笔记--循环
- Swift学习-循环
- 循环队列学习
- 推荐一门“神经网络”相关的视频课程
- bzoj 3339: Rmq Problem
- 树莓派motion摄像头监控并将图片上传百度云盘
- linux下常用命令
- Android Studio Jni环境配置 - 记录
- 循环单链表学习
- EntityFramework中常用的数据删除方式
- distinct使SQL查询除去重复的字段
- C语言网:1048: C语言程序设计教程(第三版)课后习题10.7
- eclipse经常卡死的解决方法总结
- bzoj 2453: 维护队列
- POJ 3982 序列(大数)
- Django框架使用
- jQuery制作元素在屏幕中水平垂直居中效果