-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList1.cpp
More file actions
135 lines (83 loc) · 1.22 KB
/
Copy pathLinkedList1.cpp
File metadata and controls
135 lines (83 loc) · 1.22 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include<iostream>
using namespace std;
#include "Node.cpp"
Node* takeInput()
{
int data;
cin>>data;
Node * head=NULL;
char per='y';
//cout<<"Do you want to add more nodes?"<<endl;
//cin>>per;
while(per=='y')
{
Node* newnode= new Node(data);
if(head==NULL)
{
head=newnode;
}
else
{
Node* temp=head;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=newnode;
}
cout<<"Do you want to add more nodes?"<<endl;
cin>>per;
if(per=='y'){
cout<<"add data to added node"<<endl;
cin>>data;
}
}
return head;
}
void print(Node * head)
{
//Node* temp=head;
/*
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
*/
while(head!=NULL)
{
cout<<head->data<<" ";
head=head->next;
}
cout<<endl;
}
int main()
{
Node* head=takeInput();
print(head);
//Node* tail=&n2;
/*Node n1(1);
Node* head=&n1;
Node n2(2);
n1.next=&n2;
Node n3(3);
n2.next=&n3;
Node n4(4);
n3.next=&n4;
Node n5(5);
n4.next=&n5;
print(head);
print(head);
/*
n1.next=&n2;
cout<<head->data<<" "<<head->next->data<<endl;
//cout<<" n1= "n1.data<<" n2= "<<n2.data;
//Dynamically
Node* n3=new Node(3);
n2.next= n3;
Node* n4=new Node(4);
n3->next=n4;
cout<<head->next->next->data<<" "<<head->next->next->next->data<<endl;
*/
}