创建带头结点的单链表 ,插入数据,以及输出

#include

#include 

typedef struct node{

int data;

node *next; 

}node;

//创建带头结点的单链表 

create(node *L){

L= (node*)malloc(sizeof(node));

if (L==NULL){

printf ("0");

}

else

{

L->next=NULL;

printf ("1");

}

//插入数据 、尾插法、函数前面的*表示返回一个 node 类型的指针 

 struct node *insert(node *p){

printf("输入插入的数据changdu");

int a,i,b[i];

p=(node*)malloc(sizeof(node));

node *q,*r;

//一直指向头结点 

r=p;

scanf("%d",&a);

for(i=0;i

q= (node*)malloc(sizeof(node));

printf("输入插入的数据");

scanf("%d",&b[i]);

q->data=b[i];

p->next=q;

p=p->next;

}

//返回头结点

      return r;

 int Print(node *L)  

    {  

      node *p;  

      p=L->next;  

      while(p!=NULL)  

      {  

        printf("%d ",p->data);  

        p=p->next;  

      }  

    }  

int main(){

node *L,*L1;

create(L);

L1=insert(L);

Print(L1);  

}

创建带头结点的单链表 <wbr>,插入数据,以及输出
 

猜你喜欢

转载自blog.csdn.net/ganghaodream/article/details/88092132
今日推荐