-
Notifications
You must be signed in to change notification settings - Fork 0
/
链表数字插入
48 lines (47 loc) · 841 Bytes
/
链表数字插入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// main.c
// summer exercise
//
// Created by 毛遵杰 on 2019/7/28.
// Copyright © 2019 毛遵杰. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node*next;
};
struct node*head;
int main(int argc, const char * argv[]) {
int x;
head=NULL;
printf("how many numbers?\n");
int n;
scanf("%d\n",&n);
for (int i=0;i<n;i++)
{
printf("enter the number\n");
scanf("%d\n",&x);
}
insert(x);
print();
return 0;
}
void insert(int x)
{
node*temp=(node*)malloc(sizeof(struct node));
(*temp).data=x;
(*temp).next=NULL;
head=temp;
}
void print()
{
struct node*temp=head;
printf("the list is:\n");
while(temp!=NULL)
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}