数据结构之链表(C语言)

HACKHT HACKHT 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include<stdio.h>
#include<malloc.h>
typedef struct node{
int data;
struct node *next;
}NODE;

void *InitList(NODE *L){
L=(NODE *)malloc(sizeof(NODE));
L->next=NULL;
return 0;
}


void *creat(NODE *L){
int m,i; NODE *q,*p ;
printf("qing shu ru shu mu:");
scanf("%d",&m);
printf("qing shu ru shu zi:");
q=(NODE *)malloc(sizeof(NODE));
q=L;
for(i=0;i<m;i++){
p=(NODE *)malloc(sizeof(NODE));
scanf("%d",&p->data);
p->next=NULL;
q->next=p;
q=p;}
printf("wan cheng\n");
return 0;
}


void *ListInsert(NODE *L){
int i,e,j; NODE *p,*s;
printf("Now you will push a number into the list !\n");
printf("Where do you want to push the number,pleast input the xuhao:");
scanf("%d",&i);
printf("Now the number will push before %d! \n",i);
printf("Please input your number:");
scanf("%d",&e); printf("\n");
p=L; j=0;
while(p!=NULL&&j<i-1){
p=p->next; ++j;}
if(p==NULL||j>i-1) return 0;
s=(NODE *)malloc(sizeof(NODE));
s->data=e; s->next=p->next;
p->next=s;
printf("The %d have been push into the list! \n",e);
return 0;
}

void *ListDel(NODE *L){
int i,j; NODE *p,*q;
printf("Now you will delete a number from the list! \n");
printf("Please input the number's xuhao :");
scanf("%d",&i); printf("\n");
p=L; j=0;
while(p->next!=NULL&&j<i-1){
p=p->next; ++j;}
if(p->next==NULL||j>i-1) return 0;
q=p->next; p->next=q->next;
printf("The %d is delete successfully!\n",q->data);
free(q);
return 0;
}


void PrintList(NODE *L){
NODE *p;
p=(NODE *)malloc(sizeof(NODE));
p=L->next;
while(p!=NULL){
printf("%5d",p->data);
p=p->next;}

}


void main(){
NODE *T; int n=0;
printf("1.InitList 2.ListInsert 3.ListDel 4.PrintfList 5.Exit \n");
while(n!=5){
printf("Please choose the gongneng:");
scanf("%d",&n);
switch(n){
case 1:
InitList(T);
creat(T);printf("\n");
break;
case 2:
ListInsert(T);
break;
case 3:
ListDel(T);
break;
case 4:
PrintList(T); printf("\n");
break;
case 5:
break;}
}
}
...全文

相关推荐

数据结构链表的c语言实现

此程序是用c语言编写,包含链表的实现和对于其中节点的基本操作。

caoliang100

C语言 数据结构之链表实现代码

前言 最近在复习数据结构的相关知识,感觉在初学的时候还是有很多东西没有掌握,不过现在终于算是搞得比较有头绪了,所以就在写出来和大家一起分享! 什么是链表 简单的说,链表就是由多个结点离散分配,彼此通过指针相连,每个结点只有一个前驱结点和后继结点。首节点无前驱结点,为结点无后继结点的一种存储结构。 链表的结构 头结点:链表的第一个有效结点前面的结点,头结点并不存放有效数据,也就是数据域为空,加头结点的主要目的是为了方便链表的操作。 首节点:链表的第一个有效结点,结点包含数据域和指针域。 尾结点:尾结点的指针域为空。 头指针:指向头结点的指针变量,它存放了头结点的地址(在这里注

weixin_38622827

C语言数据结构链表队列的实现

C语言数据结构链表队列的实现 1.写在前面   队列是一种和栈相反的,遵循先进先出原则的线性表。   本代码是严蔚敏教授的数据结构书上面的伪代码的C语言实现代码。   分解代码没有包含在内的代码如下: #include #include #define OK 1 #define ERROR 0 typedef int QElemtype; typedef int status; 2.代码分解 2.1对队列和节点的结构定义 typedef struct QNode //对节点的结构定义 { QElemtype data; struct QN

weixin_38574410

C语言 数据结构双向链表简单实例

双向链表的基本操作     1.利用尾插法建立一个双向链表。     2.遍历双向链表。     3.实现双向链表中删除一个指定元素。     4.在非递减有序双向链表中实现插入元素e仍有序算法。     5.判断双向链表中元素是否对称若对称返回1否则返回0。     6.设元素为正整型,实现算法把所有奇数排列在偶数之前。     7.在主函数中设计一个简单的菜单调试上述算法。 实例代码: //排序的时候因为没有说明奇数和偶数需不需要各自再排序,我就没有排序,只是将奇数放在偶数后面。 //创建链表的时候,因为这个实验没有要求输出链表的长度,所以我就输入了一个长度为n的链表。 #include

weixin_38508549

C语言数据结构实现链表逆序并输出

主要介绍了C语言数据结构实现链表逆序并输出的相关资料,需要的朋友可以参考下

weixin_38562626
评论 5
收藏 已收藏
分享
返回顶部
HACKHT
C语言 70,039 成员 243,237 内容