飞行的猪哼哼

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
#include <stdio.h>
#include <stdlib.h>
struct node
{
    int data;
    struct node*next;
};
struct node *head;
int len;
void print(struct node * head)
{
    struct node *p;
    p=head->next;
    while(p!=NULL)
    {
        printf("%d",p->data);
        if(p->next!=NULL)
        {
            printf(" ");
        }
        else
        {
            printf("\n");
        }
        p=p->next;
    }

}
void insert(int mi,int xi)
{
    struct node *p,*q;
    int i;
    p=head;
    for(i=1; i<=mi&&i<=len; i++)
    {
        p=p->next;
    }
    q=(struct node *)malloc(sizeof(struct node));
    q->data=xi;
    q->next=NULL;
    q->next=p->next;
    p->next=q;
    len++;
}


int main()
{
    int n,i,xi,mi;

    while(scanf("%d",&n)!=EOF)
    {
        head=(struct node *)malloc(sizeof(struct node));
        head->next=NULL;
        len=0;
        for(i=1; i<=n; i++)
        {

            scanf("%d %d",&mi,&xi);
            insert(mi,xi);
        }
        print(head);

    }
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
struct node
{
    int data;
    struct node*next;
};
struct node *head;
int len;
void print(struct node * head)
{
    struct node *p;
    p=head->next;
    while(p!=NULL)
    {
        printf("%d",p->data);
        if(p->next!=NULL)
        {
            printf(" ");
        }
        else
        {
            printf("\n");
        }
        p=p->next;
    }

}
void insert(int m,int x)
{
    struct node *p,*q,*t;
    int i;
    p=head;
    q=p->next;
    for(i=1; i<=m&&i<=len; i++)
    {
        p=p->next;
        q=q->next;
    }
    t=(struct node *)malloc(sizeof(struct node));
    t->data=x;
    t->next=NULL;
    p->next=t;
    t->next=q;
    len++;
}


int main()
{
    int n,i,x,m;

    while(scanf("%d",&n)!=EOF)
    {
        head=(struct node *)malloc(sizeof(struct node));
        head->next=NULL;
        len=0;
        for(i=1; i<=n; i++)
        {

            scanf("%d %d",&m,&x);
            insert(m,x);
        }
        print(head);

    }
    return 0;
}
posted on 2018-08-16 17:54  飞行的猪哼哼  阅读(39)  评论(0)    收藏  举报