-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLabwork3A.cpp
More file actions
106 lines (100 loc) · 4.22 KB
/
Labwork3A.cpp
File metadata and controls
106 lines (100 loc) · 4.22 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
#include <iostream>
#include "Node.h"
#include "LinkedList.h"
using namespace std;
int main()
{
string selectionString = "";
LinkedList newlink;
cout << "Welcome to the Linked List Program!" << endl;
while (true) {
cout << endl<<"Menu:" << endl
<< "1. Add an element" << endl
<< "2.Remove an element by value" << endl
<< "3.Access an element at index" << endl
<< "4.Insert an element at index" << endl
<< "5.Insert an element after index" << endl
<< "6.Remove an element at index" << endl
<< "7.Print the linked list" << endl
<< "8.Print the size of the linked list" << endl
<< "9.Check if the linked list is empty" << endl
<< "10.Clear the linked list" << endl
<< "11.[TASK]Find Middle Node"<<endl
<< "12.[TASK]Get Smallest Node" << endl
<< "13.[TASK]Move Smallest to Front" << endl
<< "x.Exit" << endl;
cin >> selectionString;
if (selectionString != "x") {
if (selectionString == "1") { // Doğru çalışıyor
cout << "Adding Element:";
string newelement;
cin >> newelement;
newlink.push_back(newelement);
}
else if (selectionString == "2") { // Doğru çalışıyor : Düzeltildi
cout << "Removing Element by Value:";
string removeelement;
cin >> removeelement;
newlink.erase(removeelement);
}
else if (selectionString == "3") { // Doğru çalışıyor
cout << "Access an element at index:";
int eindex;
cin >> eindex;
cout << "The element is:" << newlink.at(eindex) << endl;
}
else if (selectionString == "4") { // Doğru çalışıyor
cout << "Insert an element at index:";
int eindex;
cin >> eindex;
cout << "Value:";
string newelement;
cin >> newelement;
newlink.insert_at(eindex, newelement);
}
else if (selectionString == "5") { // HATA VAR ÜSTÜNE YAZIYOR : Düzeltildi
cout << "Insert an element after index:";
int eindex;
cin >> eindex;
cout << "Value:";
string newelement;
cin >> newelement;
newlink.insert_after(eindex, newelement);
}
else if (selectionString == "6") { // 0. INDEXI SİLMİYOR + DÜZGÜN ÇALIŞMIYOR : Düzeltildi
cout << "Remove an element at index:";
int eindex;
cin >> eindex;
newlink.erase_at(eindex);
}
else if (selectionString == "7") { // Doğru çalışıyor
cout << "Linked List:" << newlink;
}
else if (selectionString == "8") { // Doğru çalışıyor
cout << "Size of linked list:" << newlink.size();
}
else if (selectionString == "9") { // Doğru çalışıyor
cout << "Is linked list empty:" << newlink.empty();
}
else if (selectionString == "10") { // Biraz yanlız çalışıyor : Düzeltildi
cout << "Clearing linked list...";
newlink.clear();
}
//ANA FONK BİTTİ TASKLERİ YAP
else if (selectionString == "11") { // FIND MIDDLE
cout << "The middle node data:" << newlink.findMiddleNode()->data;
}
else if (selectionString == "12") {
cout << "The middle node data:" << newlink.getSmallestNode()->data;
}
else if (selectionString == "13") {
newlink.moveSmallestToFront();
cout << "The middle node data:" << newlink;
}
else {
cout << "Invalid Selection, try again..." << endl;
}
}
else if (selectionString == "x") exit(0);
}
}