代码如下:
#define _CRT_SECURE_NO_WARNINGS #include#include #include #include typedef struct linklist { int data; struct linklist* next; }node; int main(void) { node* head = (node*)malloc(sizeof(node)); head->next = NULL; node* p; p=head; int n; printf("请输入链表的长度:n"); scanf("%d", &n); printf("请输入元素:n"); for (int i = 0; i < n; i++) { node* s = (node*)malloc(sizeof(node)); scanf("%d", &s->data); p->next = s; s->next = NULL; p = s; } p = head; while (p->next != NULL) { printf("%5d", p->next ->data); p = p->next; } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)