forked from a-r-nida/HactoberFest2020-Beginers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RevLL.C
56 lines (55 loc) · 896 Bytes
/
RevLL.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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct node{
int data;
struct node * next;
};
struct node * head;
void reverse(){
struct node *temp,*prevnode,*currnode,*nextnode;
prevnode=NULL;
currnode=head;
nextnode=head;
while(currnode!=NULL){
nextnode=nextnode->next;
currnode->next=prevnode;
prevnode=currnode;
currnode=nextnode;
}
head=prevnode;
}
void main(){
struct node *temp,*newnode;
int choice;
clrscr();
head=NULL;
while(choice){
newnode = (struct node*)malloc(sizeof(struct node));
printf("enter data");
scanf("%d",&newnode->data);
newnode->next=NULL;
if(head==NULL){
head=newnode;
temp=newnode;
}
else{
temp->next=newnode;
temp=newnode;
}
printf("Do you want to continue(0,1)?");
scanf("%d",&choice);
}
temp=head;
while(temp!=NULL){
printf("%d",temp->data);
temp=temp->next;
}
reverse();
temp=head;
while(temp!=NULL){
printf("%d",temp->data);
temp=temp->next;
}
getch();
}