-
Notifications
You must be signed in to change notification settings - Fork 28
/
lists.txt
65 lines (59 loc) · 1002 Bytes
/
lists.txt
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
#include <iostream>
#include <stdlib.h>
using namespace std;
struct node {
int data;
node* link ;
};
node *head;
void input(int x,int n)
{
node * temp = new node();
temp->data = x;
temp->link = NULL;
if (n==1){
temp->link =head;
head = temp;
return;
}
node *temp1= head;
for (int i=0;i<n-2;i++ ){
temp1 = temp1->link;
}
temp->link = temp1->link;
temp1->link = temp;
}
void rev(){
node* prev = NULL;
node * current = head;
node * Next ;
while (current != NULL){
Next = current->link;
current->link= prev;
prev = current;
current = Next;
if (current->link == NULL){
current ->link = prev;
head = current;
return ;
}
}
} // ENDing of the void function
void Print (){
node* temp = head;
while (temp != NULL){
cout<<temp->data;
temp = temp->link;
}
}
int main () {
head = NULL;
input (2,1);
input (4,2);
input (6,3);
input (8,4);
Print ();
rev();
Print();
return 0;
}