文章
12
粉丝
319
获赞
10
访问
131.9k
//建立带有头结点的单链表
#include <stdio.h>
#include <stdlib.h>
typedef struct Node
{
int Element;
struct Node *Next;
}Node;
int main()
{
int n = 0, i = 4;
Node *list = (Node*)malloc(sizeof(Node)), *p, *pre = list, *temp; //list指向头结点,p和pre为遍历指针,temp指向新创建的结点
list->Next = NULL;
//建立并插入第一个结点
scanf("%d", &n);
temp = (Node*)malloc(sizeof(Node));
temp->Element = n;
temp->Next = list->Next;
list->Next = temp;
//循环4次插入余下的4个结点
while (i--)
{
pre = list;
p = pre->Next;
scanf("%d", &n);
temp = (Nod...
登录后发布评论
暂无评论,来抢沙发