线性链表C

#include<stdio.h>
#include<malloc.h>
#define NULL 0
typedef int ElemType;
typedef struct node{
	ElemType data;
	node *next;
}*Node;
void Creat_list(Node &head)//头插法插入新节点
{
	int x;
	head->next=NULL;
	Node p=new node;
	printf("请输入数据,以0结束\n");
	scanf("%d",&x);
	while(x)
	{
		Node u=new node;
		u->data=x;
		u->next=head->next;
		head->next=u;
		scanf("%d",&x);

	}

}
void Display_list(Node head)
{
	Node p=new node;
	p=head->next;
	printf("现在的LIST为:\n");
	while(p)
	{
		printf("%d\n",p->data);
		p=p->next;
	}
}
void Insert_list(Node &head,ElemType x,int n)
{
	Node p=new node;
	p=head->next;
	int i=1;
	for(i=1;i<=n;i++)
	p=p->next;
	Node u=new node;
	u->data=x;
	u->next=p->next;
	p->next=u;
	

}
void Delete_list(Node &head,int n)
{
   Node p=new node;
   Node u=new node;
	p=head->next;
	int i=1;
	for(i=1;i<=n;i++)
	p=p->next;
	u=p->next;
	p->next=u->next;
	

}
void main()
{
	printf("本程序是用头插法插入节点,因此反序乃正常现象\n");
	node head;
	
	Node p=new node;
	Creat_list(p);
	Display_list(p);
	Insert_list(p,677,2);
	Display_list(p);
	Delete_list(p,2);
	Display_list(p);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值