Add Node class, work on singly LinkedList class and examples
This commit is contained in:
15
plates/cpp-datastruct/apps/CMakeLists.txt
Normal file
15
plates/cpp-datastruct/apps/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
###############################################################################
|
||||
## Author: Shaun reserved ##
|
||||
## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
##############################################################################
|
||||
|
||||
# # Create a variable to reference our source code
|
||||
# set(DRIVER_SRC driver.cpp)
|
||||
|
||||
# # Add the executable to the build list
|
||||
# add_executable(driver ${DRIVER_SRC})
|
||||
|
||||
# # Link custom libraries to our executable
|
||||
# target_link_libraries(driver lib-datastruct)
|
||||
@@ -4,6 +4,8 @@
|
||||
// StackArray menu
|
||||
void Stack();
|
||||
|
||||
void List();
|
||||
|
||||
// Main menu
|
||||
int main ()
|
||||
{
|
||||
@@ -27,6 +29,7 @@ int main ()
|
||||
break;
|
||||
|
||||
case LISTS: // 1
|
||||
List();
|
||||
break;
|
||||
|
||||
case STACKS: // 2
|
||||
@@ -45,6 +48,74 @@ int main ()
|
||||
return 0;
|
||||
}
|
||||
|
||||
// LinkedList menu
|
||||
void List()
|
||||
{
|
||||
enum LIST_OPS {
|
||||
EXIT, APPEND, PUSH, DEQUEUE, POP, DISPLAY
|
||||
};
|
||||
bool exit = false;
|
||||
int choice;
|
||||
char val;
|
||||
LinkedList list;
|
||||
|
||||
while(!exit) {
|
||||
std::cout << "\n##### LinkedList Menu #####\n"
|
||||
<< "Enter a choice below...\n\t0. Exit"
|
||||
<< "\n\t1. Append\n\t2. Push\n\t3. Dequeue\n\t4. Pop"
|
||||
<< "\n\t5. Display\n\t6. Find\n\t7. Remove\n";
|
||||
std::cin >> choice;
|
||||
std::cin.clear();
|
||||
switch(choice) {
|
||||
case EXIT: // 0
|
||||
exit = true;
|
||||
break;
|
||||
|
||||
case APPEND: // 1
|
||||
std::cout << "Enter a character to append to our list: ";
|
||||
std::cin >> val;
|
||||
std::cin.clear();
|
||||
list.Append(val);
|
||||
break;
|
||||
|
||||
case PUSH: // 2
|
||||
std::cout << "Enter a character to push to our list: ";
|
||||
std::cin >> val;
|
||||
std::cin.clear();
|
||||
list.Push(val);
|
||||
break;
|
||||
|
||||
case DEQUEUE: // 3
|
||||
std::cout << "Enter a value to remove from the list: ";
|
||||
std::cin >> val;
|
||||
std::cin.clear();
|
||||
list.Remove(val);
|
||||
break;
|
||||
|
||||
case POP: // 4
|
||||
// list.Pop();
|
||||
list.Append('a');
|
||||
Node *tem = list.Find('a');
|
||||
list.Remove('a');
|
||||
if (tem != NULL) {
|
||||
std::cout << "Found [" << tem->data << "] within the list\n";
|
||||
}
|
||||
delete tem;
|
||||
break;
|
||||
|
||||
case DISPLAY: // 5
|
||||
list.Display();
|
||||
break;
|
||||
|
||||
default:
|
||||
std::cout << "Invalid option selected\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// StackArray menu
|
||||
void Stack()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user