链表输出

来源:互联网 发布:数据库事务的四大特性 编辑:程序博客网 时间:2024/05/01 23:20
自己试试手的,可以参考看看
#include <stdio.h>#include<stdlib.h>typedef struct LIST{int data;struct LIST *next;}S;int main(){S *head,*p,*q;int N,a;head = (LIST*)malloc(sizeof(LIST*));scanf("%d",&N);p=(LIST*)malloc(sizeof(LIST*));scanf("%d",&a);p->data=a;head->next=p;for (int i=2;i<=N;i++){q=(LIST*)malloc(sizeof(LIST*));scanf("%d",&a);q->data=a;p->next=q;p=q;}p->next = NULL;p = head->next;while(p!=NULL){printf("%d ",p->data);p = p->next;}return 0;}