From 7ebcb12569a42779f43f9709c38c6a209d2b89c2 Mon Sep 17 00:00:00 2001 From: Shaun Reed Date: Fri, 1 May 2020 00:02:45 -0400 Subject: [PATCH] Clean up old and new files --- plates/circlesinglelist/circlesinglelist.cpp | 3 +- plates/circlesinglelist/circlesinglelist.h | 4 +- plates/cpp-datastruct/CMakeLists.txt | 63 ------- plates/cpp-datastruct/apps/CMakeLists.txt | 15 -- plates/cpp-datastruct/apps/driver.cpp | 170 ----------------- .../cpp-datastruct/include/lib-datastruct.h | 48 ----- .../include/lib-datastruct.h.in | 8 - plates/cpp-datastruct/src/CMakeLists.txt | 12 -- plates/cpp-datastruct/src/lib-datastruct.cpp | 172 ------------------ plates/cpp-launcher/CMakeLists.txt | 21 --- plates/cpp-launcher/apps/CMakeLists.txt | 16 -- plates/cpp-launcher/apps/launcher.cpp | 76 -------- plates/cpp-launcher/include/lib-launcher.hpp | 37 ---- plates/cpp-launcher/src/CMakeLists.txt | 13 -- plates/cpp-launcher/src/lib-launcher.cpp | 80 -------- plates/singlelist/driver.cpp | 4 +- plates/singlelist/singlelist.cpp | 64 ++++--- plates/singlelist/singlelist.h | 6 +- 18 files changed, 43 insertions(+), 769 deletions(-) delete mode 100644 plates/cpp-datastruct/CMakeLists.txt delete mode 100644 plates/cpp-datastruct/apps/CMakeLists.txt delete mode 100644 plates/cpp-datastruct/apps/driver.cpp delete mode 100644 plates/cpp-datastruct/include/lib-datastruct.h delete mode 100644 plates/cpp-datastruct/include/lib-datastruct.h.in delete mode 100644 plates/cpp-datastruct/src/CMakeLists.txt delete mode 100644 plates/cpp-datastruct/src/lib-datastruct.cpp delete mode 100644 plates/cpp-launcher/CMakeLists.txt delete mode 100644 plates/cpp-launcher/apps/CMakeLists.txt delete mode 100644 plates/cpp-launcher/apps/launcher.cpp delete mode 100644 plates/cpp-launcher/include/lib-launcher.hpp delete mode 100644 plates/cpp-launcher/src/CMakeLists.txt delete mode 100644 plates/cpp-launcher/src/lib-launcher.cpp diff --git a/plates/circlesinglelist/circlesinglelist.cpp b/plates/circlesinglelist/circlesinglelist.cpp index a876c13..0f2390b 100644 --- a/plates/circlesinglelist/circlesinglelist.cpp +++ b/plates/circlesinglelist/circlesinglelist.cpp @@ -185,12 +185,13 @@ bool CircleSingleList::isEmpty() const * * @return int The value held at the Node at the head of our linked list */ -void CircleSingleList::peek() const +int CircleSingleList::peek() const { // If there is only one data member, a circular list node will point to itself if (!isEmpty()) std::cout << "[" << tail->next->data << "] is at the top of our list\n"; else std::cout << "Nothing to peek, our list is empty...\n"; + return tail->next->data; } /** print diff --git a/plates/circlesinglelist/circlesinglelist.h b/plates/circlesinglelist/circlesinglelist.h index 4274e47..36ea568 100644 --- a/plates/circlesinglelist/circlesinglelist.h +++ b/plates/circlesinglelist/circlesinglelist.h @@ -13,7 +13,7 @@ #include -class CircleSingleList{ +class CircleSingleList { public: CircleSingleList() : tail(NULL) {}; CircleSingleList(const CircleSingleList& rhs); @@ -25,7 +25,7 @@ class CircleSingleList{ bool replace(int val, int key); void makeEmpty(); bool isEmpty() const; - void peek() const; + int peek() const; void print() const; bool find(int val) const; diff --git a/plates/cpp-datastruct/CMakeLists.txt b/plates/cpp-datastruct/CMakeLists.txt deleted file mode 100644 index d4a8136..0000000 --- a/plates/cpp-datastruct/CMakeLists.txt +++ /dev/null @@ -1,63 +0,0 @@ -############################################################################### -## Author: Shaun reserved ## -## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ## -## ## -## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## -############################################################################## - -# Define the version of CMake -cmake_minimum_required(VERSION 3.10) -# Name and version of our project -project(DataStruct VERSION 0.1) -# Specify the C++ standard -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED True) - -# Create path variables relative to root directory (CMAKE_SOURCE_DIR) -set(APPS_DIR ./apps) -set(SRC_DIR ./src) -set(INCLUDE_DIR ./include) -set(DRIVER_SRC ${APPS_DIR}/driver.cpp) -set(LIB_DS_SRC ${SRC_DIR}/lib-datastruct.cpp) - -add_library(lib-ds ${LIB_DS_SRC}) - -add_executable(Driver ${DRIVER_SRC}) - -target_link_libraries(Driver PUBLIC lib-ds) - -target_include_directories(lib-ds PUBLIC ${INCLUDE_DIR}) - -# configure_file(${INCLUDE_DIR}/lib-datastruct.h.in ${CMAKE_BINARY_DIR}/generated/lib-datastruct.h) -# include_directories( ${CMAKE_BINARY_DIR}/generated/ ) - -# # Location of our header files -# # include_directories(./include) -# include_directories(${PROJECT_BINARY_DIR}) -# include_directories( ${CMAKE_BINARY_DIR}/generated/ ) - - -# # Additional directories to expect a CMakeLists.txt -# # add_subdirectory(src) -# # add_subdirectory(apps) - -# # Configure includes to consider cmake variables -# configure_file(${INCLUDE_DIR}/lib-datastruct.h.in ${CMAKE_BINARY_DIR}/generated/lib-datastruct.h) - -# # /apps/CMakeLists.txt -# # Create a variable to reference any sources to add -# set(LIB_DS_SRC ${SRC_DIR}/lib-datastruct.cpp) -# # Create our library -# add_library(lib-datastruct ${LIB_DS_SRC}) -# # Point the library to directories containing any includes it might need -# target_include_directories(lib-datastruct PUBLIC "${INCLUDE_DIR}") - -# # /src/CMakeLists.txt -# # Create a variable to reference our driver program source code -# set(DRIVER_SRC ${APPS_DIR}/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) - -# # target_include_directories(Driver PUBLIC "${INCLUDE_DIR}") diff --git a/plates/cpp-datastruct/apps/CMakeLists.txt b/plates/cpp-datastruct/apps/CMakeLists.txt deleted file mode 100644 index d638b84..0000000 --- a/plates/cpp-datastruct/apps/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -############################################################################### -## 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) diff --git a/plates/cpp-datastruct/apps/driver.cpp b/plates/cpp-datastruct/apps/driver.cpp deleted file mode 100644 index b35d70d..0000000 --- a/plates/cpp-datastruct/apps/driver.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include -#include - -// StackArray menu -void Stack(); - -void List(); - -// Main menu -int main () -{ - // std::cout << "Running driver program version " << DS_VERSION; - enum OPS { - EXIT, LISTS, STACKS, QUEUES - }; - - bool exit = false; - int choice; - while (!exit) { - std::cout << "\n##### Main Menu #####\n" - << "Enter a choice below...\n\t0. Exit" - << "\n\t1. Lists\n\t2. Stacks\n\t3. Queues\n"; - std::cin >> choice; - std::cin.clear(); - - switch (choice) { - case EXIT: // 0 - exit = true; - break; - - case LISTS: // 1 - List(); - break; - - case STACKS: // 2 - Stack(); - break; - - case QUEUES: // 3 - break; - - default: - std::cout << "Invalid option selected\n"; - break; - } - } - - 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() -{ - enum STACK_OPS { - EXIT, PUSH, POP, TOP, DISPLAY - }; - - StackArray stack; - bool exit = false; - int choice; - while (!exit) { - std::cout << "\n##### StackArray Menu #####\n" - << "Enter a choice below...\n\t0. Exit" - << "\n\t1. Push\n\t2. Pop\n\t3. Top\n\t4. Display\n"; - std::cin >> choice; - std::cin.clear(); - - switch (choice) { - case EXIT: // 0 - exit = true; - break; - - case PUSH: // 1 - char val; - std::cout << "Enter a character to push to our stack: "; - std::cin >> val; - std::cin.clear(); - stack.Push(val); - break; - - - case POP: // 2 - std::cout << "[" << stack.Pop() << "] has been removed from our stack\n"; - break; - - - case TOP: // 3 - std::cout << "[" << stack.Top() << "] is at the top of our stack\n"; - break; - - - case DISPLAY: // 4 - stack.Display(); - break; - - default: - std::cout << "Invalid option selected\n"; - break; - } - } - -} diff --git a/plates/cpp-datastruct/include/lib-datastruct.h b/plates/cpp-datastruct/include/lib-datastruct.h deleted file mode 100644 index 489204a..0000000 --- a/plates/cpp-datastruct/include/lib-datastruct.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef LDS_H -#define LDS_H - -#include - -class Node { - public: - Node() : next(NULL) {}; - Node(char val) : data(val), next(NULL) {}; - char data; - Node *next; -}; - -// Linked list - -class LinkedList { - - public: - LinkedList() : head(NULL), tail(NULL) {}; - void Append(char val); - void Push(char val); - void Remove(char val); - void Replace(char remove, char replace); - void Display() const; - bool isEmpty() const; - Node* Find(char val) const; - private: - Node *head, *tail; -}; - -// Array based stack - -class StackArray { - public: - StackArray() : top(EMPTY) {}; - void Push(char val); - char Pop(); - char Top() const; - void Display() const; - bool isEmpty() const; - - private: - enum { EMPTY=-1, MAX=10 }; - Node stack[MAX]; - int top; -}; - -#endif diff --git a/plates/cpp-datastruct/include/lib-datastruct.h.in b/plates/cpp-datastruct/include/lib-datastruct.h.in deleted file mode 100644 index 5e1f686..0000000 --- a/plates/cpp-datastruct/include/lib-datastruct.h.in +++ /dev/null @@ -1,8 +0,0 @@ -// #ifndef LDS_H -// #define LDS_H - -#define DS_VERSION_MINOR @DataStruct_VERSION_MINOR@ -#define DS_VERSION_MAJOR @DataStruct_VERSION_MAJOR@ -#define DS_VERSION @DataStruct_VERSION@ - -// #endif diff --git a/plates/cpp-datastruct/src/CMakeLists.txt b/plates/cpp-datastruct/src/CMakeLists.txt deleted file mode 100644 index 5c38076..0000000 --- a/plates/cpp-datastruct/src/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -############################################################################### -## 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 any sources to add -# set(LIB_DS_SRC lib-datastruct.cpp) - -# # Create our library -# add_library(lib-datastruct ${LIB_DS_SRC}) diff --git a/plates/cpp-datastruct/src/lib-datastruct.cpp b/plates/cpp-datastruct/src/lib-datastruct.cpp deleted file mode 100644 index b717103..0000000 --- a/plates/cpp-datastruct/src/lib-datastruct.cpp +++ /dev/null @@ -1,172 +0,0 @@ -#include - -// LinkedList - -void LinkedList::Append(char val) -{ - Node *temp = new Node(val); - - if (isEmpty()) { - this->tail = this->head = temp; - // head->next = tail; - return; - } - else { - tail->next = temp; - tail = temp; - return; - } -} - -void LinkedList::Push(char val) -{ - Node *temp = new Node(val); - - if (isEmpty()) - { - this->head = this->tail = temp; - return; - } - else { - temp->next = head; - this->head = temp; - return; - } -} - -void LinkedList::Remove(char val) -{ - Node *foundNode = new Node; - - if (isEmpty()) { - // if list is empty - std::cout << "Error: List is empty\n"; - return; - } - else if (this->head->data == val) { - // check the head node, return if found val - foundNode = this->head; - std::cout << "[" << foundNode->data << "] has been removed from our list\n"; - this->head = foundNode->next; - delete foundNode; - // Does this set head to NULL? - // this->head = NULL; - return; - } - - Node *temp = head; - while (temp->next->data != val) { - temp = temp->next; - if (temp->next == NULL) { - std::cout << "Value [" << val << "] not found in our list\n"; - return; - } - } - foundNode = temp->next; - // If we made it our of the loop, we found val at the next node - temp->next = foundNode->next; - std::cout << "[" << foundNode->data << "] has been removed from our list\n"; - delete foundNode; - return; -} - -void LinkedList::Replace(char remove, char replace) -{ - return; -} - -Node* LinkedList::Find(char val) const -{ - Node *foundNode(NULL); - Node *temp = head; - - if(isEmpty()) { - std::cout << "Error: The list is empty\n"; - return foundNode; - } - - bool found = false; - - while (!found && temp->next != NULL) { - if(temp->next->data == val) { - found = true; - foundNode = temp->next; - std::cout << "[" << foundNode->data << "] has been found in our list\n"; - // temp->next = foundNode->next; - // delete foundNode; - } - temp = temp->next; - } - return foundNode; -} - -void LinkedList::Display() const -{ - Node *temp = head; - while (temp != NULL) { - std::cout << "[" << temp->data << "] | "; - temp = temp->next; - } - return; -} - -bool LinkedList::isEmpty() const -{ - return this->head == NULL; -} - -// StackArray - -void StackArray::Push(char val) -{ - - if (top < MAX && !isEmpty()) { - this->stack[++top].data = val; - } - else if (isEmpty()) { - this->stack[++top].data = val; - } - else { - std::cout << "Error: stack is full!\n"; - } - return; -} - -char StackArray::Pop() -{ - - if (!isEmpty()) { - char temp = this->Top(); - this->top -= 1; - return temp; - } - return '\0'; -} - -char StackArray::Top() const -{ - return this->stack[top].data; -} - -void StackArray::Display() const -{ - if (isEmpty()) { - std::cout << "Error: Stack is empty\n"; - return; - } - - int tempTop = this->top; - while (tempTop >= 0) { - std::cout << "Value at stack [" << tempTop << "]: " - << this->stack[tempTop].data << std::endl; - tempTop--; - } - - return; -} - -bool StackArray::isEmpty() const -{ - return this->top <= EMPTY; -} - diff --git a/plates/cpp-launcher/CMakeLists.txt b/plates/cpp-launcher/CMakeLists.txt deleted file mode 100644 index 8e81555..0000000 --- a/plates/cpp-launcher/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ - -############################################################################### -## Author: Shaun Reed ## -## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ## -## ## -## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## -############################################################################## - -# Define the version of CMake -cmake_minimum_required(VERSION 2.8) - -# Define the your project name -project(cpp-launcher) - -# Include any directories the compiler may need -include_directories(./include) - -# Point CMake to look for more CMakeLists within the following directories -add_subdirectory(src) -add_subdirectory(apps) - diff --git a/plates/cpp-launcher/apps/CMakeLists.txt b/plates/cpp-launcher/apps/CMakeLists.txt deleted file mode 100644 index ca4a62b..0000000 --- a/plates/cpp-launcher/apps/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -############################################################################### -## Author: Shaun Reed ## -## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ## -## ## -## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## -############################################################################## - -# Create a reference / variable to refer to our source code -set(LAUNCHER_SRC launcher.cpp) - -# Add our executable, naming it and linking it to our source code -add_executable(launcher ${LAUNCHER_SRC}) - -# Link to our custom library, defined in c-cmake/src/ -target_link_libraries(launcher lib-launcher) - diff --git a/plates/cpp-launcher/apps/launcher.cpp b/plates/cpp-launcher/apps/launcher.cpp deleted file mode 100644 index 9de049f..0000000 --- a/plates/cpp-launcher/apps/launcher.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/*############################################################################# -## Author: Shaun Reed ## -## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ## -## ## -## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## -############################################################################## -## launcher.cpp -*/ - -#include -#include - -int main () { - // Because the launcher is this executable.. (main() will become our exe) - // Initialize the user choice to launcher problem at runtime - int pChoice = LAUNCH; - - // Cast the integer pChoice into an assignment for our Problem enum - // No failsafes needed here since we know pChoice = LAUNCH - Problem pSelect = static_cast(pChoice); - - do - { - printf("\nWelcome to the cpp launcher!\n" - "Input the problem number to run the example.\n"); - - //ProblemList(); List and explain problem selection - //ProblemSelect(); Select problem, handle errors, return result to &pSelect - - std::cin >> pChoice; - - if(pChoice == LAUNCH) - { // Ensure that pSelect = LAUNCH and restart - pSelect = static_cast(pChoice); - std::cin.ignore(std::numeric_limits::max(), '\n'); - RunProblem(pSelect); - continue; - } - else if ( pChoice > QTY ) - { // If we have entered a value too large, restart - std::printf("\nThe value you entered is too large." - "\nPlease enter a value below %d\n", QTY); - pSelect = Problem::Launch; // Set our launcher to restart and continue - continue; - } - - if (!std::cin ) - { // Check for cin error state - std::cin.clear(); - std::cin.ignore(); - pChoice = ERROR; - } - // One last input check for other error values - if (pChoice < EXIT) pChoice = ERROR; - - // Cast the integer pChoice into an assignment for our Problem enum - pSelect = static_cast(pChoice); - - /* - * We should expect a clear input buffer at this point - * Clear cin up to next endline to prepare for the next input - * Depends on include for numeric_limits - */ - std::cin.ignore(std::numeric_limits::max(), '\n'); - - // Run the problem, print exit, or print error. - RunProblem(pSelect); - - // Run loop until invalid or exit input recieved - } while (pChoice > EXIT || pChoice == LAUNCH); - // Exit the launcher if the selection is in range - // Exit if pSelect is set to ERROR state value - - return 0; -} - diff --git a/plates/cpp-launcher/include/lib-launcher.hpp b/plates/cpp-launcher/include/lib-launcher.hpp deleted file mode 100644 index d7abe77..0000000 --- a/plates/cpp-launcher/include/lib-launcher.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/*############################################################################# -## Author: Shaun Reed ## -## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ## -## ## -## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## -############################################################################## -## lib-launcher.hpp -*/ - -#include -#include - -// Define our constants -// These are used for ranges within our control loops -const int QTY = 5; -const int EXIT = 0; -const int ERROR = -1; -const int LAUNCH = 99; - -/* An enumeration for use with RunProblem() when selecting which problem to run - * This is meant to be expanded as needed. - * Be sure to add a corresponding case within RunProblem() - * - * @Launcher (LAUNCH 99) the value used for the launcher as a problem number - * @Exit (EXIT 0) is the normal exit index - * @Error (ERROR -1) is considered an error - */ -enum class Problem -{ Launch = 99, Error = -1, Exit, One, Two, Three, Four, Five }; - -/* This function allows for selection of the next problem to run. - * - * @param pSelect - The index to use within our enumeration. - * Allows for easy integer to problem selection. - */ -void RunProblem(Problem pSelect); - diff --git a/plates/cpp-launcher/src/CMakeLists.txt b/plates/cpp-launcher/src/CMakeLists.txt deleted file mode 100644 index 131d022..0000000 --- a/plates/cpp-launcher/src/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -############################################################################### -## Author: Shaun Reed ## -## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ## -## ## -## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## -############################################################################## - -# Create any links we might need -set(LIB_LAUNCHER_SRC lib-launcher.cpp) - -# Define our library within CMake and link to the source code -add_library(lib-launcher ${LIB_LAUNCHER_SRC}) - diff --git a/plates/cpp-launcher/src/lib-launcher.cpp b/plates/cpp-launcher/src/lib-launcher.cpp deleted file mode 100644 index 08a031d..0000000 --- a/plates/cpp-launcher/src/lib-launcher.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/*############################################################################# -## Author: Shaun Reed ## -## Legal: All Content (c) 2019 Shaun Reed, all rights reserved ## -## ## -## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ## -############################################################################## -## lib-launcher.cpp -*/ - -#include - -/* This function allows for selection of the next problem to run. - * - * @param pSelect - The index to use within our enumeration. - * Allows for easy integer to problem selection. - */ -void RunProblem(Problem pSelect) { - - switch (pSelect) { - - case Problem::One: - std::printf("\nYou are on problem 1!\n" - "Press enter to continue."); - std::cin.ignore(); - break; - - case Problem::Two: - std::printf("\nYou are on problem 2!\n" - "Press enter to continue."); - std::cin.ignore(); - break; - - case Problem::Three: - std::printf("\nYou are on problem 3!\n" - "Press enter to continue."); - std::cin.ignore(); - break; - - case Problem::Four: - std::printf("\nYou are on problem 4!\n" - "Press enter to continue."); - std::cin.ignore(); - break; - - case Problem::Five: - std::printf("\nYou are on problem 5!\n" - "Press enter to continue."); - std::cin.get(); - break; - - case Problem::Exit: - std::printf("\nYou are on problem 0! This is a safe exit.\n" - "Press enter to continue."); - std::cin.ignore(); - break; - - case Problem::Error: - std::printf("\nYou are on problem -1! This is considered and error.\n" - "Press enter to exit."); - std::cin.ignore(); - break; - - case Problem::Launch: - // Do nothing, break and let main() restart the launcher - std::printf("\nRestarting the launcher...\n" - "Press enter to continue."); - std::cin.ignore(); - break; - - default: - std::printf("\nYou have entered an invalid value." - "\nPress Enter to try again."); - //ProblemList(); - break; - - } - - return; -} - diff --git a/plates/singlelist/driver.cpp b/plates/singlelist/driver.cpp index be746e1..8a47ba9 100644 --- a/plates/singlelist/driver.cpp +++ b/plates/singlelist/driver.cpp @@ -51,7 +51,7 @@ int main() std::cin >> key; std::cin.clear(); if (testList.insert(val, key)) { - std::cout << "List after inserting [" + std::cout << "List after inserting [" << val << "] at [" << key << "]: \n"; testList.print(); } @@ -91,7 +91,7 @@ int main() std::cin >> key; std::cin.clear(); if (testList.replace(val, key)) { - std::cout << "List after replacing [" + std::cout << "List after replacing [" << key << "] by [" << val << "]: \n"; testList.print(); } diff --git a/plates/singlelist/singlelist.cpp b/plates/singlelist/singlelist.cpp index ac2bf8f..52d54bd 100644 --- a/plates/singlelist/singlelist.cpp +++ b/plates/singlelist/singlelist.cpp @@ -10,13 +10,14 @@ #include "singlelist.h" + /****************************************************************************** * Constructors, Destructors, Operators - *****************************************************************************/ + *****************************************************************************/ -/** +/** copy constructor * @brief Construct a new SingleList::SingleList object from an existing one - * + * * @param rhs SingleList object */ SingleList::SingleList(const SingleList& rhs) @@ -39,8 +40,8 @@ SingleList::SingleList(const SingleList& rhs) /** operator= * @brief Assign two SingleList objects equal using copy constr and class destr * Pass the rhs by value to create local copy, swap its contents - * Destructor called on previous SingleList data at the end of this scope - * + * Destructor called on previous SingleList data at the end of this scope + * * @param rhs SingleList object passed by value * @return SingleList A deep copy of the rhs SingleList object */ @@ -51,7 +52,7 @@ SingleList SingleList::operator=(SingleList rhs) return *this; } -/** +/** destructor * @brief Destroy the SingleList::SingleList object */ SingleList::~SingleList() @@ -59,19 +60,20 @@ SingleList::~SingleList() makeEmpty(); } + /****************************************************************************** * Public Member Functions - *****************************************************************************/ + *****************************************************************************/ /** insert * @brief Inserts a value to the head of our linked list - * + * * @param x The value to be inserted */ bool SingleList::insert(int val) { bool inserted = insert(val, head); - if (inserted) + if (inserted) std::cout << "[" << val << "] was inserted into the list\n"; else std::cout << "[" << val << "] could not be inserted into the list\n"; return inserted; @@ -80,14 +82,14 @@ bool SingleList::insert(int val) /** insert at * @brief Inserts a value in the place of a given key * Key Node found is moved to the newNode->next positon - * + * * @param key The value to search for to determine insert location * @param val The value to be inserted into the list */ bool SingleList::insert(int val, int key) { bool inserted = insert(val, key, head); - if (inserted) + if (inserted) std::cout << "[" << val << "] was inserted into the list\n"; else std::cout << "[" << val << "] could not be inserted into the list\n"; return inserted; @@ -95,7 +97,7 @@ bool SingleList::insert(int val, int key) /** remove * @brief Removes a value in the list by calling a private member and handling output - * + * * @param val Value to be removed from the list * @return true If the value was removed from the list * @return false If the value was not removed from the list @@ -103,7 +105,7 @@ bool SingleList::insert(int val, int key) bool SingleList::remove(int val) { bool removed = remove(val, head); - if (removed) + if (removed) std::cout << "[" << val << "] was removed from the list\n"; else std::cout << "[" << val << "] could not be removed from the list\n"; return removed; @@ -111,7 +113,7 @@ bool SingleList::remove(int val) /** replace * @brief Replaces a value in the list by calling a private member and handling output - * + * * @param val Value to insert into the list * @param key Value to be replaced within the list * @return true If the key has been replaced in the list by val @@ -120,7 +122,7 @@ bool SingleList::remove(int val) bool SingleList::replace(int val, int key) { bool replaced = replace(val, key, head); - if (replaced) + if (replaced) std::cout << "[" << key << "] was replaced by [" << val << "] in the list\n"; else std::cout << "[" << key << "] could not be replaced by [" << val << "] in the list\n"; return replaced; @@ -147,7 +149,7 @@ void SingleList::makeEmpty() /** isEmpty * @brief Determine if the SingleList is empty - * + * * @return true If the SingleList::head is NULL * @return false If the SingleList::head contains data */ @@ -158,14 +160,15 @@ bool SingleList::isEmpty() const /** peek * @brief returns the value at the SingleList::head - * + * * @return int The value held at the Node pointed to by SingleList::head */ -void SingleList::peek() const +int SingleList::peek() const { - if (!isEmpty()) + if (!isEmpty()) std::cout << "[" << head->data << "] is at the top of our list\n"; else std::cout << "Nothing to peek, our list is empty...\n"; + return head->data; } /** print @@ -180,7 +183,7 @@ void SingleList::print() const /** find * @brief Calls to the private member find() and handles return cases - * + * * @param val The value to search for within our SingleList * @return true If the value was found in this SingleList * @return false If the value was not found in this SingleList @@ -192,18 +195,19 @@ bool SingleList::find(int val) const std::cout << "[" << val << "] Was not found in our list\n"; return false; } - + std::cout << "[" << result->data << "] Was found in our list\n"; return true; } + /****************************************************************************** * Private Member Functions - *****************************************************************************/ + *****************************************************************************/ /** insert * @brief Private member to handle inserting value into the list - * + * * @param val Value to be inserted * @param head The head of the list to insert the value into * @return true If the value was inserted @@ -215,13 +219,13 @@ bool SingleList::insert(int val, Node *&head) // If the list is not empty, update next pointer to head node if (!isEmpty()) newNode->next = head; // Always set head to our newNode - head = newNode; + head = newNode; return true; } /** insert at * @brief Private member to handle inserting a value at a key within our list - * + * * @param val Value to be inserted * @param key Key value to search for within the list * @param head Head node of the list to insert to @@ -247,7 +251,7 @@ bool SingleList::insert(int val, int key, Node *&head) /** remove * @brief Private member to remove values from the list - * + * * @param val Value to be removed * @param head Head of the list to remove the value from * @return true If the value has been removed from the list @@ -272,7 +276,7 @@ bool SingleList::remove(int val, Node *&head) /** replace * @brief Private member to replace values within the list - * + * * @param val Value to insert into the list * @param key Value to be replaced within the list * @param head Head of the list to replace the value @@ -289,7 +293,7 @@ bool SingleList::replace(int val, int key, Node *&head) /** find * @brief Find and return a Node which contains the given value - * + * * @param val The value to search for within our SingleList * @return SingleList::Node* A pointer to the Node containing the search value */ @@ -310,7 +314,7 @@ SingleList::Node* SingleList::find(int val, Node *start) const /** findPrevious * @brief Find and return the Node before a given value - * + * * @param val The value to search for within our SingleList * @return SingleList::Node* A pointer to the Node previous to the given value */ @@ -330,7 +334,7 @@ SingleList::Node* SingleList::findPrevious(int val, Node *start) const /** print * @brief Output the contents of a SingleList from the given Node to NULL - * + * * @param start The Node to begin traversing output from */ void SingleList::print(Node *start) const diff --git a/plates/singlelist/singlelist.h b/plates/singlelist/singlelist.h index 24bcda2..f398471 100644 --- a/plates/singlelist/singlelist.h +++ b/plates/singlelist/singlelist.h @@ -13,8 +13,8 @@ ## singlelist.h */ -#ifndef LINKEDLIST_H -#define LINKEDLIST_H +#ifndef SINGLELIST_H +#define SINGLELIST_H #include @@ -30,7 +30,7 @@ class SingleList{ bool replace(int val, int key); void makeEmpty(); bool isEmpty() const; - void peek() const; + int peek() const; void print() const; bool find(int val) const;