Clean up old and new files

This commit is contained in:
Shaun Reed 2020-05-01 00:02:45 -04:00
parent 4eb25a22b1
commit 7ebcb12569
18 changed files with 43 additions and 769 deletions

View File

@ -185,12 +185,13 @@ bool CircleSingleList::isEmpty() const
* *
* @return int The value held at the Node at the head of our linked list * @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 there is only one data member, a circular list node will point to itself
if (!isEmpty()) if (!isEmpty())
std::cout << "[" << tail->next->data << "] is at the top of our list\n"; std::cout << "[" << tail->next->data << "] is at the top of our list\n";
else std::cout << "Nothing to peek, our list is empty...\n"; else std::cout << "Nothing to peek, our list is empty...\n";
return tail->next->data;
} }
/** print /** print

View File

@ -13,7 +13,7 @@
#include <iostream> #include <iostream>
class CircleSingleList{ class CircleSingleList {
public: public:
CircleSingleList() : tail(NULL) {}; CircleSingleList() : tail(NULL) {};
CircleSingleList(const CircleSingleList& rhs); CircleSingleList(const CircleSingleList& rhs);
@ -25,7 +25,7 @@ class CircleSingleList{
bool replace(int val, int key); bool replace(int val, int key);
void makeEmpty(); void makeEmpty();
bool isEmpty() const; bool isEmpty() const;
void peek() const; int peek() const;
void print() const; void print() const;
bool find(int val) const; bool find(int val) const;

View File

@ -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}")

View File

@ -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)

View File

@ -1,170 +0,0 @@
#include <lib-datastruct.h>
#include <iostream>
// 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;
}
}
}

View File

@ -1,48 +0,0 @@
#ifndef LDS_H
#define LDS_H
#include <iostream>
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

View File

@ -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

View File

@ -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})

View File

@ -1,172 +0,0 @@
#include <lib-datastruct.h>
// 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;
}

View File

@ -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)

View File

@ -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)

View File

@ -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 <iostream>
#include <lib-launcher.hpp>
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<Problem>(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<Problem>(pChoice);
std::cin.ignore(std::numeric_limits<std::streamsize>::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<Problem>(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 <limits> for numeric_limits<streamsize>
*/
std::cin.ignore(std::numeric_limits<std::streamsize>::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;
}

View File

@ -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 <iostream>
#include <limits>
// 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);

View File

@ -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})

View File

@ -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 <lib-launcher.hpp>
/* 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;
}

View File

@ -10,11 +10,12 @@
#include "singlelist.h" #include "singlelist.h"
/****************************************************************************** /******************************************************************************
* Constructors, Destructors, Operators * Constructors, Destructors, Operators
*****************************************************************************/ *****************************************************************************/
/** /** copy constructor
* @brief Construct a new SingleList::SingleList object from an existing one * @brief Construct a new SingleList::SingleList object from an existing one
* *
* @param rhs SingleList object * @param rhs SingleList object
@ -51,7 +52,7 @@ SingleList SingleList::operator=(SingleList rhs)
return *this; return *this;
} }
/** /** destructor
* @brief Destroy the SingleList::SingleList object * @brief Destroy the SingleList::SingleList object
*/ */
SingleList::~SingleList() SingleList::~SingleList()
@ -59,6 +60,7 @@ SingleList::~SingleList()
makeEmpty(); makeEmpty();
} }
/****************************************************************************** /******************************************************************************
* Public Member Functions * Public Member Functions
*****************************************************************************/ *****************************************************************************/
@ -161,11 +163,12 @@ bool SingleList::isEmpty() const
* *
* @return int The value held at the Node pointed to by 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"; std::cout << "[" << head->data << "] is at the top of our list\n";
else std::cout << "Nothing to peek, our list is empty...\n"; else std::cout << "Nothing to peek, our list is empty...\n";
return head->data;
} }
/** print /** print
@ -197,6 +200,7 @@ bool SingleList::find(int val) const
return true; return true;
} }
/****************************************************************************** /******************************************************************************
* Private Member Functions * Private Member Functions
*****************************************************************************/ *****************************************************************************/

View File

@ -13,8 +13,8 @@
## singlelist.h ## singlelist.h
*/ */
#ifndef LINKEDLIST_H #ifndef SINGLELIST_H
#define LINKEDLIST_H #define SINGLELIST_H
#include <iostream> #include <iostream>
@ -30,7 +30,7 @@ class SingleList{
bool replace(int val, int key); bool replace(int val, int key);
void makeEmpty(); void makeEmpty();
bool isEmpty() const; bool isEmpty() const;
void peek() const; int peek() const;
void print() const; void print() const;
bool find(int val) const; bool find(int val) const;