forked from vijay532/CompetitiveSources
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListReverse.c
More file actions
66 lines (63 loc) · 1.1 KB
/
LinkedListReverse.c
File metadata and controls
66 lines (63 loc) · 1.1 KB
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
63
64
65
66
//gcc 5.4.0
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
void getRev(struct node* head)
{
if(head==NULL)
{
return;
}
getRev(head->next);
printf("%d ",head->data);
}
void print(struct node* head)
{
if(head==NULL)
{
return;
}
printf("%d ",head->data);
print(head->next);
}
void push(struct node** head_ref, int new_data)
{
struct node* new_node = (struct node*)malloc(sizeof(struct node));
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
//return ;
}
int main()
{
int n,m;
scanf("%d",&n);
struct node* head = NULL;
struct node* p,*q;
p = (struct node*)malloc(sizeof(struct node));
scanf("%d",&m);
p->data = m;
p->next = NULL;
head = p;
for(int i=1;i<n;i++)
{
scanf("%d",&m);
q=(struct node*)malloc(sizeof(struct node));
q->data=m;
q->next=NULL;
p->next=q;
p=p->next;
//push(&head,m);
}
//print(head);
getRev(head);
}
/*
4
10 11 12 14
14 12 11 10
*/