-
Notifications
You must be signed in to change notification settings - Fork 0
/
linklist.c
62 lines (53 loc) · 1.23 KB
/
linklist.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
// define a node structure
struct Node
{
int data;
struct Node *list;
};
// function to create a new node
struct Node* CreateNode(int data){
struct Node *newNode;
newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data;
newNode->list;
return newNode;
}
// function to add insert the node at the end
void insertAtEnd(struct Node** head, int data)
{
struct Node* newNode = CreateNode(data);
if(*head = NULL){
*head = newNode;
return;
}
struct Node* current = *head;
while(current-> list != NULL){
current = current->list;
}
current->list = newNode;
}
//fuction to display the linked list
void displaylist(struct Node* head){
struct Node* current = head;
while (current != NULL){
printf("%d -> ",current->data);
current = current->list;
}
printf("NUll\n");
}
int main()
{
struct Node *head, *Current;
head = malloc(sizeof(struct Node));
Current = malloc(sizeof(struct Node));
head->data = 45;
head->list = NULL;
Current->data = 54;
Current->list = NULL;
head->list = Current;
printf("%d\n", head->data);
printf("%d\n", Current->data);
return 0;
}