-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinked_List.cpp
More file actions
93 lines (72 loc) · 1.16 KB
/
Linked_List.cpp
File metadata and controls
93 lines (72 loc) · 1.16 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
#include <iostream>
using namespace std;
class node
{
public:
int data;
node *next;
};
node *head = NULL;
void insertatbeg(int val)
{
node *p = new node;
p->data = val;
p->next = NULL;
if(head == NULL)
{
head = p;
}
else
{
p->next = head;
head = p;
}
}
void insertatend(int val)
{
node *p = new node;
p->data = val;
p->next = NULL;
node*temp = head;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next = p;
}
void insertatposition(int val, int pos)
{
node *p = new node;
p->data = val;
p->next = NULL;
node *temp = head;
int i = 1;
while (i < pos-1)
{
temp = temp->next;
i++;
}
p->next = temp->next;
temp->next = p;
}
void traverse()
{
node *temp=head;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp = temp->next;
}
}
int main()
{
insertatbeg(23);
insertatbeg(29);
insertatbeg(60);
insertatend(29);
insertatend(59);
insertatend(93);
insertatposition(62,4);
traverse();
return 0;
}