84 std::shared_ptr<link>
last;
91 first = std::make_shared<link>();
100 void erase(
int old_elem);
102 std::shared_ptr<link>
search(
int find_elem);
112 if (
last ==
nullptr) {
125 first->succ() = std::make_shared<link>(new_elem);
128 last->succ() = std::make_shared<link>(new_elem);
139 first->succ() = std::make_shared<link>(new_elem);
142 std::shared_ptr<link> t = std::make_shared<link>(new_elem);
143 t->succ() =
first->succ();
154 std::cout <<
"List is Empty!";
157 std::shared_ptr<link> t =
first;
158 std::shared_ptr<link> to_be_removed =
nullptr;
159 while (t !=
last && t->succ()->val() != old_elem) {
163 std::cout <<
"Element not found\n";
166 to_be_removed = t->succ();
167 t->succ() = t->succ()->succ();
168 to_be_removed.reset();
169 if (t->succ() ==
nullptr) {
183 std::cout <<
"List is Empty!";
186 std::shared_ptr<link> t =
first;
187 while (t->succ() !=
nullptr) {
188 std::cout << t->succ()->val() <<
"\t";
199 std::cout <<
"List is Empty!";
202 std::shared_ptr<link> t =
first;
203 while (t !=
last && t->succ()->val() != find_elem) {
207 std::cout <<
"Element not found\n";
210 std::cout <<
"Element was found\n";
228 std::cout <<
"\n1. Insert";
229 std::cout <<
"\n2. Delete";
230 std::cout <<
"\n3. Search";
231 std::cout <<
"\n4. Print";
232 std::cout <<
"\n0. Exit";
233 std::cout <<
"\n\nEnter you choice : ";
237 std::cout <<
"\nQuitting the program...\n";
240 std::cout <<
"\nEnter the element to be inserted : ";
243 if (data_structures::linked_list::isDigit(s)) {
247 std::cout <<
"Wrong Input!\n";
251 std::cout <<
"\nEnter the element to be removed : ";
253 if (data_structures::linked_list::isDigit(s)) {
257 std::cout <<
"Wrong Input!\n";
261 std::cout <<
"\nEnter the element to be searched : ";
263 if (data_structures::linked_list::isDigit(s)) {
265 std::shared_ptr<data_structures::linked_list::link> found =
268 std::cout <<
"Wrong Input!\n";
276 std::cout <<
"Invalid Input\n" << std::endl;
279 }
while (choice != 0);
int pvalue
value of the current link
std::shared_ptr< link > & succ()
std::shared_ptr< link > psucc
pointer to the next value on the list
void push_front(int new_elem)
void push_back(int new_elem)
std::shared_ptr< link > first
link before the actual first element
std::shared_ptr< link > search(int find_elem)
std::shared_ptr< link > last
last link on the list
bool isDigit(const std::string &s)
Functions for singly linked list algorithm.