-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked list1.c
45 lines (41 loc) · 935 Bytes
/
linked list1.c
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
#include<stdio.h>
#include<stdlib.h>
struct Node{
int data;
struct Node *next;
};
struct Node *head = NULL;
struct Node *tail = NULL;
struct Node *Creat_A_NewNode(int val){
struct Node *nn = (struct Node*)malloc(sizeof(struct Node));
nn->data = val;
nn->next = NULL;
return nn;
}
void PrintALinkedList(struct Node *head){
struct Node *temp = head;
while(temp!=NULL){
printf("%d ",temp->data);
temp = temp->next;
}
}
void Creat_A_LInked_List(int val){
struct Node* nn = Creat_A_NewNode(val);
if(head == NULL){
// printf("hi");
head = nn;
tail = nn;
}
else{
tail->next = nn;
tail = tail->next;
}
}
int main(){
for(int i = 0 ; i < 5 ; i++){
int val;
scanf("%d",&val);
Creat_A_LInked_List(val);
}
PrintALinkedList(head);
}