链表基本操作
来源:互联网 发布:十香cosplay淘宝 编辑:程序博客网 时间:2024/05/22 00:23
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedefstruct stu{
int d;
struct stu *l;
}st;
void xj(st *h)//生成单链表
{ st*l;
l=h;
int m;
scanf("%d",&m);
h=(st *)malloc(sizeof(st));
while(m--)
{
st*s;
s=new st;
scanf("%d",&s->d);
l->l=s;
l=s;
}
l->l=NULL;
}
void shc(st *h)//输出链表
{ h=h->l;
while(h->l!=NULL)
{
printf("%d",h->d);
h=h->l;
}
printf("%d\n",h->d);
}
void chr(st *h)//按大小插入元素
{int n;
scanf("%d",&n);
h=h->l;
while(h!=NULL)
{
if(n<=h->l->d)
{
st*s;
s=new st;
s->d=n;
s->l=h->l;
h->l=s;
break;
}
else
h=h->l;
}
}
void shac(st *h)//删除链表第n个元素
{int n;
scanf("%d",&n);
int k=0;
while(h!=NULL)
{if(k==n-1)
{
st*s;
s=new st;
s=h->l;
h->l=h->l->l;
free(s);
break;
}
h=h->l;
k++;
}
}
void dz(st *h)//倒置链表
{ st*l;
l=new st;
l=h->l->l;
h->l->l=NULL;
while(l!=NULL)
{ st*s;
s=new st;
s->d=l->d;
s->l=h->l;
h->l=s;
l=l->l;
}
}
int main()
{ st*h,*h1;
h=new st;
h1=new st;
h=h1;
xj(h);
h=h1;
shc(h);
h=h1;
chr(h);
h=h1;
shc(h);
h=h1;
shac(h);
h=h1;
shc(h);
h=h1;
dz(h);
shc(h);
return0;
}
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- 链表基本操作
- Flag破灭
- UVA 12657 Boxes in a Line(双向链表)
- Python之经典类VS新式类和Supper
- Python基础入门之输入输出
- 实例讲解TP5中关联模型
- 链表基本操作
- HDU 4857 拓扑排序+优先最大值
- 高质量c/c++编程学习之二:命名规则
- (zoj1204)Additive equations
- HDU5861(线段树好题)
- Windows教程
- java学习笔记
- INTRODUCTION TO WRITING ARM SHELLCODE
- Android笔记(22)Wheelview选择器