-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedLindel.cpp
More file actions
90 lines (79 loc) · 1.41 KB
/
linkedLindel.cpp
File metadata and controls
90 lines (79 loc) · 1.41 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
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
class Node
{
public:
int num;
Node* next;
};
void append(Node** href, int val)
{
Node* newnode = new Node();
newnode->num = val;
newnode->next = NULL;
Node* temp = *href;
if(temp == NULL)
{
*href = newnode;
return;
}
while(temp->next != NULL)
{
temp = temp->next;
}
temp->next = newnode;
return;
}
void push(Node**href,int val)
{
Node* newnode = new Node();
Node* temp = *href;
newnode->num = val;
newnode->next = temp;
*href = newnode;
}
void printlist(Node** loop)
{
Node* pop = *loop;
while(pop != NULL)
{
cout << pop->num << " ";
pop = pop->next;
}
}
void delete1(Node* href,int key, int lim)
{
Node* temp = href;
int count1 = 1;
while(temp->next != NULL && count1 != key-1)
{
temp = temp->next;
count1++;
}
Node* prev = temp;
prev->next = temp->next->next;
}
int main()
{
int n;
cin >> n;
int arr[n];
Node* head = NULL;
for(int i = 0; i < n; i++)
cin >> arr[i];
for(int i = 0; i < n; i++)
append(&head, arr[i]);
printlist(&head);
cout << "\n";
push(&head, 8);
printlist(&head);
cout << "\n";
cout << "deleting node " << endl;
int d;
cin >> d;
delete1(head, d, n);
printlist(&head);
return 0;
}