-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinked_List.cpp
More file actions
113 lines (107 loc) · 1.56 KB
/
Copy pathLinked_List.cpp
File metadata and controls
113 lines (107 loc) · 1.56 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
#include<bits/stdc++.h>
using namespace std;
//Ctreating node
struct Node
{
int data;
struct Node *next;
};
typedef struct Node *node;// define a pointer have struct Node type
//inserting begin
void Insert_Begin(node *p,int x)
{
node q;
q= (node)malloc(sizeof(struct Node));
q->data =x;
q->next =*p;
*p=q;
}
void Insert_End(node *p,int x)
{
node q,temp;
temp = *p;
(node)malloc(sizeof(struct Node));
q->data = x;
q->next =NULL;
if(*p==NULL)
{
*p=q;
}
else
{
while(temp->next!=NULL){
temp= temp->next;
}
temp->next = q;
}
}
void Insert_Middle(node *p,int position,int x)
{
node q,temp;
int flag =0,count=0;
temp = *p;
while(temp!=NULL&&flag ==0){
if(count==position)
{
q =(node)malloc(sizeof(struct Node));
q->data= x;
q->next= temp->next;
temp->next=q;
flag =1;
}
temp= temp->next;
count++;
}
if(flag==0)
{
cout<<" Can't find the position to insert";
}
}
// REMOVE
void Remove_Begin(node *p)
{
node q;
q = *p;
*p = (*p)->next;
q->next = NULL;
free(q);
}
void Remove_End(node *p)
{
node q,temp;
temp= *p;
while(temp->next!=NULL){
q= temp;
temp = temp->next;
}
q->next = NULL;
free(temp);
}
void Remove_Middle(node *p,int position)
{
node q,temp;
temp =*p;
int flag =0,count=0;
while(temp->next!=NULL&&flag==0){
if(count==position)
{
q= temp->next;
temp->next=q->next;
free(q);
flag =1;
}
}
if(flag==0)
{
cout<<"Can't find the position to remove";
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
node *p=NULL;
int x;
cin>>x;
return 0;
}