SDUT2116数据结构实验之链表一:顺序建立链表

来源:互联网 发布:linux xampp mysql 编辑:程序博客网 时间:2024/05/05 19:40
#include<bits/stdc++.h>using namespace std;struct node{    int data;    struct node *next;}*head,*tail,*p;int n;void built(){    head=(struct node *)malloc(sizeof(struct node));    tail=head;    while(n--)    {        p=(struct node *)malloc(sizeof(struct node));        scanf("%d",&p->data);        tail->next=p;        tail=p;    }    tail->next=NULL;}void print(){    p=head->next;    while(p)    {        printf("%d",p->data);        if(p->next)            printf(" ");        p=p->next;    }}int main(){    scanf("%d",&n);    built();    print();}

0 0
原创粉丝点击