forked from bhawna-menghani/DSA_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_insertion.cpp
More file actions
73 lines (71 loc) · 1.32 KB
/
Copy path1_insertion.cpp
File metadata and controls
73 lines (71 loc) · 1.32 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
#include <bits/stdc++.h>
using namespace std;
class Node
{
public:
int data;
Node *next;
};
/*********at beginning**************/
void insbeg(Node **head, int x)
{
Node *n = new Node();
n->data = x;
n->next = *head;
*head = n;
}
/**************at end**************/
void insend(Node **head, int y)
{
Node *n = new Node();
Node *last = *head;
n->data = y;
n->next = NULL;
if (*head == NULL)
{
*head = n;
return;
}
else
{
while (last->next != NULL)
{
last = last->next;
}
last->next = n;
}
}
/**********at point**************/
void inspoint(Node *prev, int x)
{
if (prev != NULL)
{
Node *n = new Node();
n->data = x;
n->next = prev->next;
prev->next = n;
}
}
/*********traversal***************/
void traversal(Node *node)
{
while (node != NULL)
{
cout << " " << node->data;
node = node->next;
}
}
/************************************/
int main()
{
Node *head = NULL;
insbeg(&head, 1);
insend(&head, 9);
insbeg(&head, 2);
insbeg(&head, 3);
insbeg(&head, 4);
insend(&head, 9);
inspoint(head->next, 22);
cout << "linked list is ";
traversal(head);
}