-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedListOne.cc
More file actions
64 lines (55 loc) · 1.13 KB
/
linkedListOne.cc
File metadata and controls
64 lines (55 loc) · 1.13 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
#include<iostream>
#include<list>
using namespace std;
struct Node
{
int data;
struct Node *next;
}*head;
Node* Reverse(Node *head)
{
Node *next = head;
if(!head){
return head;
}
list<int> l;
while(next){
l.push_front(next->data);
next = next->next;
}
list<int>::iterator it = l.begin();
cout<<"lfront"<<l.front()<<"\n";
cout<<"*it"<<*it<<"\n";
Node* ne = new Node;
ne->data = *it;
head = ne;
++it;
cout<<"ne->data"<<ne->data<<"\n";
cout<<"head->data"<<head->data<<"\n";
while(it!=l.end()){
Node *n = new Node;
n->data = *it;
ne->next = n;
ne = ne->next;
++it;
}
ne->next = NULL;
cout<<"ne->data"<<ne->data<<"\n";
cout<<"head->data"<<head->data<<"\n";
cout<<"head->next->data"<<head->next->data<<"\n";
cout<<head<<"\n";
return head;
}
int main(){
head = new Node;
cout<<head<<"\n";
head->data = 2;
head->next = new Node;
head->next->data = 3;
head->next->next = NULL;
head = Reverse(head);
cout<<head<<"\n";
cout<<head->data<<"\n";
cout<<head->next->data<<"\n";
return 0;
}