-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedl.cpp
More file actions
87 lines (82 loc) · 1.81 KB
/
Copy pathlinkedl.cpp
File metadata and controls
87 lines (82 loc) · 1.81 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
#include "linkedl.h"
#include <iostream>
using namespace std;
node::node(int r, string b, int bc, string jt, float f)
{
{
rollno = r;
branch = b;
branch_code = bc;
job_title = jt;
ctc = f;
next = NULL;
}
}
void sll_insert(node **head, int r, string b, int bc, string jt, float f)
{
node *newNode = new node(r, b, bc, jt, f);
newNode->next = *head;
*head = newNode;
}
void sll_print(node **head)
{
if(*head == NULL)
{
cout << "Linked list is empty, nothing to print!" << endl;
return;
}
node *ptr = *head;
while(ptr != NULL)
{
cout << "Roll no: " << ptr-> rollno << " Role: " << ptr->job_title << " CTC: " << ptr->ctc <<endl;
ptr = ptr -> next;
}
cout << "\n";
}
void sll_delete(node **head, int r, string b, int bc, string jt, float f)
{
int position = sll_search(head, r, b, bc, jt, f);
if(position == 0)
{
node *temp = (*head) -> next;
*head = temp;
}
else if(position != -1)
{
node *ptr = *head;
for (int i = 1; ptr != NULL && i < position; i++)
{
ptr = ptr -> next;
}
if((ptr -> next) -> next != NULL)
{
node *temp = (ptr -> next) -> next;
ptr -> next = temp;
}
else
{
node *t = ptr -> next;
ptr -> next = NULL;
free(t);
}
}
else
{
cout << "The company and role you are looking for does not exist!\n";
}
}
int sll_search(node **head, int r, string b, int bc, string jt, float f)
{
int s = 0;
node *ptr = *head;
while(ptr != NULL)
{
if(ptr -> rollno == r && ptr->job_title == jt)
{
return s;
}
ptr = ptr -> next;
s++;
}
return -1;
}