师--链表的结点插入
来源:互联网 发布:淘宝合并下单 编辑:程序博客网 时间:2024/05/29 16:59
Problem Description
Input
Output
Example Input
41 11 20 3100 4
Example Output
3 1 2 4
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node * next;
};
struct node * create(int n)
{
int m,x,count=0,count1=0;
struct node * head,*tail,*p,*q;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
while(n--)
{
scanf("%d%d",&m,&x);
if(m>count)
{
p=(struct node *)malloc(sizeof(struct node));
p->next=tail->next;
tail->next=p;
tail=p;
p->data=x;
count++;
}
else if(!m)
{
p=(struct node *)malloc(sizeof(struct node));
p->next=head->next;
head->next=p;
p->data=x;
count++;
}
else
{
q=head->next;
count1=1;
while(count1!=m)
{
q=q->next;
count1++;
}
p=(struct node *)malloc(sizeof(struct node));
p->next=q->next;
q->next=p;
if(!p->next)
tail=p;
p->data=x;
count++;
}
}
return head;
}
void show(struct node * head)
{
struct node * p;
p=head->next;
while(p->next!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
printf("%d\n",p->data);
}
int main()
{
struct node * head;
int n;
while(scanf("%d",&n)!=EOF)
{
head=create(n);
show(head);
}
return 0;
}
- 师--链表的结点插入
- 师--链表的结点插入
- 师--链表的结点插入
- 师--链表的结点插入
- 师--链表的结点插入
- 师--链表的结点插入
- 师--链表的结点插入
- 师--链表的结点插入
- 师--链表的结点插入
- 师--链表的结点插入
- 链表结点的插入
- 头结点链表的三种插入结点方式
- sdut oj2874 师--链表的结点插入
- 双向链表结点的插入
- 双向链表插入结点的理解。
- 链表C 链表的结点插入
- 《剑指offer》链表的结点的插入删除
- 关于链表的新建,删除结点,插入结点的代码
- 乾坤合一:Linux设备驱动之块设备驱动
- linux查过的问题
- Android的增量更新
- 机器学习之神经网络基础概念
- 使用maven解决mapper映射文件不发布问题
- 师--链表的结点插入
- Xcode8:"subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0"的解决
- 类锁 synchronized对象锁 和 Lock对象锁
- 配置本地和共享yum源,定制属于自己的yum仓库
- 03-树3 Tree Traversals Again (25分)
- -----线段树模板
- CentOS Linux中zip压缩和unzip解压缩命令详解
- 基于springmvc实现上传下载的案例
- MySQL相关问题汇总