forked from kavyanshpandey/hacktoberfest-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReverseLinkedList.c
55 lines (47 loc) · 996 Bytes
/
ReverseLinkedList.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
#include<stdio.h>
#include<stdlib.h>
struct node{
int data;
struct node * next;
};
void Listtraversal(struct node *ptr)
{
while(ptr!=NULL)
{
printf("%d ",ptr->data);
ptr=ptr->next;
}
}
void function1(struct node* head)
{
if(head == NULL)
return;
function1(head->next);
printf("%d ", head->data);
}
int main()
{
struct node *head;
struct node *second;
struct node *third;
struct node *fourth;
struct node *fifth;
head= (struct node *)malloc(sizeof(struct node*));
second=(struct node*)malloc(sizeof(struct node*));
third=(struct node*)malloc(sizeof(struct node *));
fourth=(struct node *)malloc(sizeof(struct node *));
fifth=(struct node*)malloc(sizeof(struct node));
head->data=7;
head->next=second;
second->data=3;
second->next=third;
third->data=8;
third->next=fourth;
fourth->data=9;
fourth->next=fifth;
fifth->data=1;
fifth->next=NULL;
Listtraversal(head);
printf(" \nthe reverse Linked List is - \n");
function1(head);
}