普通链表 2

xiaoxiao2021-02-27  187

#include<bits/stdc++.h> struct node { int data; struct node *next; }; int main() { struct node *head,*p,*q,*t; int i,n,a; scanf("%d",&n); head = NULL; for(i=1;i<=n;i++) { scanf("%d",&a); p=(struct node *)malloc(sizeof(struct node)); p->data=a; p->next=NULL; if(head==NULL) head=p; else q->next=p; q=p; } t=head; while(t!=NULL) { printf("%d ",t->data); t=t->next; } return 0; }
转载请注明原文地址: https://www.6miu.com/read-13091.html

最新回复(0)