阅读背景:

第15周 啊哈算法 链表:用指针链表和数组模拟链表

来源:互联网 

问题及代码:

/*
功能:链表中插入数据并输出所有数据 
*/
#include<stdio.h>
#include<stdlib.h>
struct node 
 {
   int date;
   struct node *next;
 };

 int main()
  {
    struct node *head,*p,*q,*t;
    int i,a,n;

    head=NULL;
    scanf("%d",&n);

    for(i=1;i<=n;i++)
     {
       scanf("%d",&a);
       p=(struct node *)malloc(sizeof(struct node));
       p->date=a;
       p->next=NULL;

       if(head==NULL)
          head=p;
       else
          q->next=p;
       q=p;
       }
t=head;
scanf("%d",&a);
while(t!=NULL)
 {
   if(t->next->date>a)
    {
     p=(struct node *)malloc(sizeof(struct node));
     p->date=a;
     p->next=t->next;
     t->next=p;
     break;
    }
   t=t->next;
 }  
     //输入链表中所有数
     t=head;
     while(t!=NULL)
       {
        printf("%d",t->date);
        t=t->next;
        }
  getchar();getchar();
  return 0;
}/*
功能:链表中插入数据并输出所有数据 
*/
#include&l



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: