-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsll3.c
46 lines (45 loc) · 962 Bytes
/
sll3.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
#include <stdio.h>
#include <malloc.h>
struct node{
int data;
struct node * next;
};
struct sll{
struct node * head;
struct node * last;
};
struct sll create(struct sll a, int n){
a.head = (struct node *) malloc(sizeof(struct node));
a.head->data = n;
a.head->next = NULL;
a.last = a.head;
return a;
}
struct sll insert_last(struct sll a,int n){
struct node *next = (struct node *) malloc(sizeof(struct node));
next->data = n;
a.last->next = next;
a.last = next;
return a;
}
void display(struct sll a){
struct node *temp;
temp = a.head;
if (temp != NULL){
while(temp != NULL){
printf("data is : %d\n",temp->data);
temp = temp->next;
}
}
}
int main() {
struct sll a;
a = create(a,10);
a = insert_last(a,15);
a = insert_last(a,25);
a = insert_last(a,35);
a = insert_last(a,45);
printf("%d",a.last->data);
display(a);
return 0 ;
}