From 70bb8c81be4c482fd1d7a62a7aae2250bc12e735 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Fri, 5 Jun 2020 09:11:26 -0400 Subject: [PATCH 01/12] remove duplicate line Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25e8dc4a4..957be35f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,6 @@ if(DOXYGEN_FOUND) set(DOXYGEN_INLINE_SOURCES YES) set(DOXYGEN_CREATE_SUBDIRS YES) set(DOXYGEN_EXTRACT_PRIVATE YES) - set(DOCYGEN_GENERATE_TREEVIEW YES) set(DOXYGEN_GENERATE_TREEVIEW YES) set(DOXYGEN_STRIP_CODE_COMMENTS NO) set(DOXYGEN_EXT_LINKS_IN_WINDOW YES) From ff6cb07b9cdfd6988bb1d75217671d0e0b52a49b Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Fri, 5 Jun 2020 21:55:12 -0400 Subject: [PATCH 02/12] enable cmake in subfolders of data_structures --- data_structures/CMakeLists.txt | 4 ++++ data_structures/cll/CMakeLists.txt | 5 +++++ data_structures/cll/makefile | 11 ----------- data_structures/queue/CMakeLists.txt | 5 +++++ data_structures/queue/makefile | 11 ----------- data_structures/stk/CMakeLists.txt | 11 +++++++++++ 6 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 data_structures/cll/CMakeLists.txt delete mode 100644 data_structures/cll/makefile create mode 100644 data_structures/queue/CMakeLists.txt delete mode 100644 data_structures/queue/makefile create mode 100644 data_structures/stk/CMakeLists.txt diff --git a/data_structures/CMakeLists.txt b/data_structures/CMakeLists.txt index 7840c8349..fab3c5642 100644 --- a/data_structures/CMakeLists.txt +++ b/data_structures/CMakeLists.txt @@ -16,3 +16,7 @@ foreach( testsourcefile ${APP_SOURCES} ) install(TARGETS ${testname} DESTINATION "bin/data_structures") endforeach( testsourcefile ${APP_SOURCES} ) + +add_subdirectory(cll) +add_subdirectory(queue) +add_subdirectory(stk) diff --git a/data_structures/cll/CMakeLists.txt b/data_structures/cll/CMakeLists.txt new file mode 100644 index 000000000..cb18eb347 --- /dev/null +++ b/data_structures/cll/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable( cll + cll.cpp + main_cll.cpp +) +install(TARGETS cll DESTINATION "bin/data_structures") diff --git a/data_structures/cll/makefile b/data_structures/cll/makefile deleted file mode 100644 index 0f8734eab..000000000 --- a/data_structures/cll/makefile +++ /dev/null @@ -1,11 +0,0 @@ -CC= g++ -CFLAGS = -c -Wall - -all: cll -cll.o: cll.cpp main_cll.cpp - $(CC) $(CFLAGS) cll.cpp main_cll.cpp -cll: cll.o - $(CC) main_cll.o cll.o -o cll - -clean: - rm *o cll diff --git a/data_structures/queue/CMakeLists.txt b/data_structures/queue/CMakeLists.txt new file mode 100644 index 000000000..969936730 --- /dev/null +++ b/data_structures/queue/CMakeLists.txt @@ -0,0 +1,5 @@ +add_executable( test_queue + queue.cpp + test_queue.cpp +) +install(TARGETS test_queue DESTINATION "bin/data_structures") diff --git a/data_structures/queue/makefile b/data_structures/queue/makefile deleted file mode 100644 index 420909804..000000000 --- a/data_structures/queue/makefile +++ /dev/null @@ -1,11 +0,0 @@ -CC= g++ -CFLAGS = -c -Wall - -all: test_queue -queue.o: queue.cpp - $(CC) $(CFLAGS) queue.cpp -test_queue: queue.o - $(CC) test_queue.cpp queue.o -o queue - -clean: - rm *o queue diff --git a/data_structures/stk/CMakeLists.txt b/data_structures/stk/CMakeLists.txt new file mode 100644 index 000000000..c348ca853 --- /dev/null +++ b/data_structures/stk/CMakeLists.txt @@ -0,0 +1,11 @@ +add_executable( stack + stack.cpp + main.cpp +) +add_executable( test_stack + stack.cpp + test_stack.cpp +) +install(TARGETS stack DESTINATION "bin/data_structures") +install(TARGETS test_stack DESTINATION "bin/data_structures") +install(FILES students.txt DESTINATION "bin/data_structures") From 30cf80c35dcd63c26278c94ac309095dd5d6cfe0 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 10:44:02 -0400 Subject: [PATCH 03/12] create and link object file --- data_structures/stk/CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/data_structures/stk/CMakeLists.txt b/data_structures/stk/CMakeLists.txt index c348ca853..30149ec06 100644 --- a/data_structures/stk/CMakeLists.txt +++ b/data_structures/stk/CMakeLists.txt @@ -1,11 +1,15 @@ +add_library(libstack OBJECT stack.h stack.cpp) add_executable( stack - stack.cpp main.cpp ) -add_executable( test_stack - stack.cpp +target_link_libraries(stack PUBLIC libstack) +# set_target_properties(stack PROPERTIES LINKER_LANGUAGE CXX) + +add_executable( test_stack test_stack.cpp ) +target_link_libraries(test_stack PUBLIC libstack) + install(TARGETS stack DESTINATION "bin/data_structures") install(TARGETS test_stack DESTINATION "bin/data_structures") install(FILES students.txt DESTINATION "bin/data_structures") From 36510f1fdc0bd92bf89159c1b112c8286d38a3c6 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 12:16:45 -0400 Subject: [PATCH 04/12] cpp lint fixes and instantiate template classes --- data_structures/stk/main.cpp | 23 ++++++-------- data_structures/stk/makefile | 13 -------- data_structures/stk/stack.cpp | 32 +++++++++++-------- data_structures/stk/stack.h | 8 ++--- data_structures/stk/test_stack.cpp | 50 ++++++++++++++++-------------- 5 files changed, 59 insertions(+), 67 deletions(-) delete mode 100644 data_structures/stk/makefile diff --git a/data_structures/stk/main.cpp b/data_structures/stk/main.cpp index 44b7984e0..11215ac4b 100644 --- a/data_structures/stk/main.cpp +++ b/data_structures/stk/main.cpp @@ -8,29 +8,26 @@ * ./main student.txt ************************************************************ * */ -#include +#include #include #include #include #include -#include "stack.cpp" #include "stack.h" -using namespace std; - int main(int argc, char* argv[]) { double GPA; double highestGPA; - string name; + std::string name; assert(argc == 2); - ifstream infile; - stack stk; + std::ifstream infile; + stack stk; infile.open(argv[1]); - cout << fixed << showpoint; - cout << setprecision(2); + std::cout << std::fixed << std::showpoint; + std::cout << std::setprecision(2); infile >> GPA >> name; highestGPA = GPA; @@ -44,12 +41,12 @@ int main(int argc, char* argv[]) { } infile >> GPA >> name; } - cout << "Highest GPA: " << highestGPA << endl; - cout << "Students the highest GPA are: " << endl; + std::cout << "Highest GPA: " << highestGPA << std::endl; + std::cout << "Students the highest GPA are: " << std::endl; while (!stk.isEmptyStack()) { - cout << stk.top() << endl; + std::cout << stk.top() << std::endl; stk.pop(); } - cout << endl; + std::cout << std::endl; return 0; } diff --git a/data_structures/stk/makefile b/data_structures/stk/makefile deleted file mode 100644 index e965d2044..000000000 --- a/data_structures/stk/makefile +++ /dev/null @@ -1,13 +0,0 @@ -CC= g++ -CFLAGS = -c -Wall - -all: main test_stack -stack.o: stack.cpp - $(CC) $(CFLAGS) stack.cpp -test_stack: stack.o - $(CC) test_stack.cpp stack.o -o stk -main: stack.o - $(CC) main.cpp stack.o -o main - -clean: - rm *o stk main diff --git a/data_structures/stk/stack.cpp b/data_structures/stk/stack.cpp index bfa8a353e..23aa3c05a 100644 --- a/data_structures/stk/stack.cpp +++ b/data_structures/stk/stack.cpp @@ -1,8 +1,7 @@ -#include "stack.h" -#include -#include +#include "./stack.h" -using namespace std; +#include +#include /* Default constructor*/ template @@ -19,13 +18,13 @@ stack::~stack() {} template void stack::display() { node *current = stackTop; - cout << "Top --> "; + std::cout << "Top --> "; while (current != NULL) { - cout << current->data << " "; + std::cout << current->data << " "; current = current->next; } - cout << endl; - cout << "Size of stack: " << size << endl; + std::cout << std::endl; + std::cout << "Size of stack: " << size << std::endl; } /* Determine whether the stack is empty */ @@ -68,20 +67,22 @@ void stack::pop() { delete temp; size--; } else { - cout << "Stack is empty !" << endl; + std::cout << "Stack is empty !" << std::endl; } } /* Operator "=" */ template -stack stack::operator=(stack &otherStack) { +stack &stack::operator=(const stack &otherStack) { node *newNode, *current, *last; - if (stackTop != NULL) /* If stack is no empty, make it empty */ + /* If stack is no empty, make it empty */ + if (stackTop != NULL) { stackTop = NULL; - if (otherStack.stackTop == NULL) + } + if (otherStack.stackTop == NULL) { stackTop = NULL; - else { + } else { current = otherStack.stackTop; stackTop = new node; stackTop->data = current->data; @@ -101,3 +102,8 @@ stack stack::operator=(stack &otherStack) { size = otherStack.size; return *this; } + +#include +/** force instantiate to export the type class */ +template class stack; +template class stack; diff --git a/data_structures/stk/stack.h b/data_structures/stk/stack.h index da7788b73..e038440a1 100644 --- a/data_structures/stk/stack.h +++ b/data_structures/stk/stack.h @@ -1,6 +1,6 @@ /* This class specifies the basic operation on a stack as a linked list */ -#ifndef STACK_H -#define STACK_H +#ifndef DATA_STRUCTURES_STK_STACK_H_ +#define DATA_STRUCTURES_STK_STACK_H_ /* Definition of the node */ template @@ -22,11 +22,11 @@ class stack { void pop(); /* Remove the top element of the stack */ void clear(); - stack operator=(stack &otherStack); + stack &operator=(const stack &otherStack); // Overload "=" the assignment operator. private: node *stackTop; /* Pointer to the stack */ int size; }; -#endif +#endif // DATA_STRUCTURES_STK_STACK_H_ diff --git a/data_structures/stk/test_stack.cpp b/data_structures/stk/test_stack.cpp index 098027dfd..aa636916f 100644 --- a/data_structures/stk/test_stack.cpp +++ b/data_structures/stk/test_stack.cpp @@ -1,56 +1,58 @@ #include -#include "stack.cpp" -#include "stack.h" -using namespace std; +#include "./stack.h" int main() { stack stk; - cout << "---------------------- Test construct ----------------------" - << endl; + std::cout << "---------------------- Test construct ----------------------" + << std::endl; stk.display(); - cout << "---------------------- Test isEmptyStack ----------------------" - << endl; + std::cout + << "---------------------- Test isEmptyStack ----------------------" + << std::endl; if (stk.isEmptyStack()) - cout << "PASS" << endl; + std::cout << "PASS" << std::endl; else - cout << "FAIL" << endl; - cout << "---------------------- Test push ----------------------" << endl; - cout << "After pushing 10 20 30 40 into stack: " << endl; + std::cout << "FAIL" << std::endl; + std::cout << "---------------------- Test push ----------------------" + << std::endl; + std::cout << "After pushing 10 20 30 40 into stack: " << std::endl; stk.push(10); stk.push(20); stk.push(30); stk.push(40); stk.display(); - cout << "---------------------- Test top ----------------------" << endl; + std::cout << "---------------------- Test top ----------------------" + << std::endl; int value = stk.top(); if (value == 40) - cout << "PASS" << endl; + std::cout << "PASS" << std::endl; else - cout << "FAIL" << endl; - cout << "---------------------- Test pop ----------------------" << endl; + std::cout << "FAIL" << std::endl; + std::cout << "---------------------- Test pop ----------------------" + << std::endl; stk.display(); stk.pop(); stk.pop(); - cout << "After popping 2 times: " << endl; + std::cout << "After popping 2 times: " << std::endl; stk.display(); - cout << "---------------------- Test overload = operator " - "----------------------" - << endl; + std::cout << "---------------------- Test overload = operator " + "----------------------" + << std::endl; stack stk1; - cout << "stk current: " << endl; + std::cout << "stk current: " << std::endl; stk.display(); - cout << endl << "Assign stk1 = stk " << endl; + std::cout << std::endl << "Assign stk1 = stk " << std::endl; stk1 = stk; stk1.display(); - cout << endl << "After pushing 8 9 10 into stk1:" << endl; + std::cout << std::endl << "After pushing 8 9 10 into stk1:" << std::endl; stk1.push(8); stk1.push(9); stk1.push(10); stk1.display(); - cout << endl << "stk current: " << endl; + std::cout << std::endl << "stk current: " << std::endl; stk.display(); - cout << "Assign back stk = stk1:" << endl; + std::cout << "Assign back stk = stk1:" << std::endl; stk = stk1; stk.display(); return 0; From cf8920852e6af313f490a583af05d2b564722abb Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 12:25:51 -0400 Subject: [PATCH 05/12] cpp lint fixes and instantiate template classes Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- data_structures/queue/CMakeLists.txt | 4 ++- data_structures/queue/queue.cpp | 21 ++++++++------- data_structures/queue/queue.h | 28 +++++++++---------- data_structures/queue/test_queue.cpp | 40 ++++++++++++++-------------- data_structures/stk/main.cpp | 2 +- 5 files changed, 50 insertions(+), 45 deletions(-) diff --git a/data_structures/queue/CMakeLists.txt b/data_structures/queue/CMakeLists.txt index 969936730..434d3bb45 100644 --- a/data_structures/queue/CMakeLists.txt +++ b/data_structures/queue/CMakeLists.txt @@ -1,5 +1,7 @@ +add_library(libqueue OBJECT queue.h queue.cpp) add_executable( test_queue - queue.cpp test_queue.cpp ) +target_link_libraries(test_queue PUBLIC libqueue) + install(TARGETS test_queue DESTINATION "bin/data_structures") diff --git a/data_structures/queue/queue.cpp b/data_structures/queue/queue.cpp index a7055bb14..9d5f9b9df 100644 --- a/data_structures/queue/queue.cpp +++ b/data_structures/queue/queue.cpp @@ -1,8 +1,7 @@ -#include "queue.h" -#include -#include +#include "./queue.h" -using namespace std; +#include +#include /* Default constructor*/ template @@ -20,13 +19,13 @@ queue::~queue() {} template void queue::display() { node *current = queueFront; - cout << "Front --> "; + std::cout << "Front --> "; while (current != NULL) { - cout << current->data << " "; + std::cout << current->data << " "; current = current->next; } - cout << endl; - cout << "Size of queue: " << size << endl; + std::cout << std::endl; + std::cout << "Size of queue: " << size << std::endl; } /* Determine whether the queue is empty */ @@ -75,6 +74,10 @@ void queue::deQueue() { delete temp; size--; } else { - cout << "Queue is empty !" << endl; + std::cout << "Queue is empty !" << std::endl; } } + +#include +/** force instantiate to export the type class */ +template class queue; diff --git a/data_structures/queue/queue.h b/data_structures/queue/queue.h index d1305fc81..d55ee3864 100644 --- a/data_structures/queue/queue.h +++ b/data_structures/queue/queue.h @@ -1,31 +1,31 @@ /* This class specifies the basic operation on a queue as a linked list */ -#ifndef QUEUE_H -#define QUEUE_H +#ifndef DATA_STRUCTURES_QUEUE_QUEUE_H_ +#define DATA_STRUCTURES_QUEUE_QUEUE_H_ -/* Definition of the node */ +/** Definition of the node */ template struct node { Kind data; node *next; }; -/* Definition of the queue class */ +/** Definition of the queue class */ template class queue { public: - void display(); /* Show queue */ - queue(); /* Default constructor*/ - ~queue(); /* Destructor */ - bool isEmptyQueue(); /* Determine whether the queue is empty */ - void enQueue(Kind item); /* Add new item to the queue */ - Kind front(); /* Return the first element of the queue */ - void deQueue(); /* Remove the top element of the queue */ + void display(); /**< Show queue */ + queue(); /**< Default constructor*/ + ~queue(); /**< Destructor */ + bool isEmptyQueue(); /**< Determine whether the queue is empty */ + void enQueue(Kind item); /**< Add new item to the queue */ + Kind front(); /**< Return the first element of the queue */ + void deQueue(); /**< Remove the top element of the queue */ void clear(); private: - node *queueFront; /* Pointer to the front of the queue */ - node *queueRear; /* Pointer to the rear of the queue */ + node *queueFront; /**< Pointer to the front of the queue */ + node *queueRear; /**< Pointer to the rear of the queue */ int size; }; -#endif +#endif // DATA_STRUCTURES_QUEUE_QUEUE_H_ diff --git a/data_structures/queue/test_queue.cpp b/data_structures/queue/test_queue.cpp index 7f0923f78..387ccf2f7 100644 --- a/data_structures/queue/test_queue.cpp +++ b/data_structures/queue/test_queue.cpp @@ -1,41 +1,41 @@ #include #include -#include "queue.cpp" -#include "queue.h" -using namespace std; +#include "./queue.h" int main() { - queue q; - cout << "---------------------- Test construct ----------------------" - << endl; + queue q; + std::cout << "---------------------- Test construct ----------------------" + << std::endl; q.display(); - cout << "---------------------- Test isEmptyQueue ----------------------" - << endl; + std::cout + << "---------------------- Test isEmptyQueue ----------------------" + << std::endl; if (q.isEmptyQueue()) - cout << "PASS" << endl; + std::cout << "PASS" << std::endl; else - cout << "FAIL" << endl; - cout << "---------------------- Test enQueue ----------------------" - << endl; - cout << "After Hai, Jeff, Tom, Jkingston go into queue: " << endl; + std::cout << "FAIL" << std::endl; + std::cout << "---------------------- Test enQueue ----------------------" + << std::endl; + std::cout << "After Hai, Jeff, Tom, Jkingston go into queue: " << std::endl; q.enQueue("Hai"); q.enQueue("Jeff"); q.enQueue("Tom"); q.enQueue("Jkingston"); q.display(); - cout << "---------------------- Test front ----------------------" << endl; - string value = q.front(); + std::cout << "---------------------- Test front ----------------------" + << std::endl; + std::string value = q.front(); if (value == "Hai") - cout << "PASS" << endl; + std::cout << "PASS" << std::endl; else - cout << "FAIL" << endl; - cout << "---------------------- Test deQueue ----------------------" - << endl; + std::cout << "FAIL" << std::endl; + std::cout << "---------------------- Test deQueue ----------------------" + << std::endl; q.display(); q.deQueue(); q.deQueue(); - cout << "After Hai, Jeff left the queue: " << endl; + std::cout << "After Hai, Jeff left the queue: " << std::endl; q.display(); return 0; } diff --git a/data_structures/stk/main.cpp b/data_structures/stk/main.cpp index 11215ac4b..a6048c4c9 100644 --- a/data_structures/stk/main.cpp +++ b/data_structures/stk/main.cpp @@ -14,7 +14,7 @@ #include #include -#include "stack.h" +#include "./stack.h" int main(int argc, char* argv[]) { double GPA; From e7b7d453b24b74afc9fc165f03f8fcd598415349 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 12:31:34 -0400 Subject: [PATCH 06/12] cpplint - ignore `build/include` Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- .github/workflows/awesome_forkflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/awesome_forkflow.yml b/.github/workflows/awesome_forkflow.yml index 05094bdd1..088d9829c 100644 --- a/.github/workflows/awesome_forkflow.yml +++ b/.github/workflows/awesome_forkflow.yml @@ -167,7 +167,7 @@ jobs: print("cpplint:") for cpp_file in cpp_files: - subprocess.run(["cpplint", "--filter=-legal/copyright", cpp_file], check=True, text=True) + subprocess.run(["cpplint", "--filter=-legal/copyright,-build/include", cpp_file], check=True, text=True) print("g++:") # compile_exts = tuple(".c .c++ .cc .cpp .cu .cxx".split()) From f1af8c150ae7ee82374d72f38e8abd35d59b3531 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 12:35:35 -0400 Subject: [PATCH 07/12] disable redundant gcc compilation in cpplint workflow Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- .github/workflows/awesome_forkflow.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/awesome_forkflow.yml b/.github/workflows/awesome_forkflow.yml index 088d9829c..93b630d05 100644 --- a/.github/workflows/awesome_forkflow.yml +++ b/.github/workflows/awesome_forkflow.yml @@ -169,11 +169,11 @@ jobs: for cpp_file in cpp_files: subprocess.run(["cpplint", "--filter=-legal/copyright,-build/include", cpp_file], check=True, text=True) - print("g++:") + # print("g++:") # compile_exts = tuple(".c .c++ .cc .cpp .cu .cxx".split()) # compile_files = [file for file in cpp_files if file.lower().endswith(compile_exts)] - for cpp_file in cpp_files: - subprocess.run(["g++", cpp_file], check=True, text=True) + # for cpp_file in cpp_files: + # subprocess.run(["g++", cpp_file], check=True, text=True) upper_files = [file for file in cpp_files if file != file.lower()] if upper_files: From 57a951173aae83805ffae1d5af48ac2cb316eb71 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 12:56:10 -0400 Subject: [PATCH 08/12] template header files contain function codes as well and removed redundant subfolders Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- data_structures/CMakeLists.txt | 2 - data_structures/queue.h | 88 ++++++++++++++ data_structures/queue/CMakeLists.txt | 7 -- data_structures/queue/queue.cpp | 83 ------------- data_structures/queue/queue.h | 31 ----- data_structures/stack.h | 111 ++++++++++++++++++ data_structures/stk/CMakeLists.txt | 15 --- data_structures/stk/stack.cpp | 109 ----------------- data_structures/stk/stack.h | 32 ----- data_structures/{stk => }/student.txt | 0 data_structures/{queue => }/test_queue.cpp | 0 data_structures/{stk => }/test_stack.cpp | 0 .../{stk/main.cpp => test_stack_students.cpp} | 0 13 files changed, 199 insertions(+), 279 deletions(-) create mode 100644 data_structures/queue.h delete mode 100644 data_structures/queue/CMakeLists.txt delete mode 100644 data_structures/queue/queue.cpp delete mode 100644 data_structures/queue/queue.h create mode 100644 data_structures/stack.h delete mode 100644 data_structures/stk/CMakeLists.txt delete mode 100644 data_structures/stk/stack.cpp delete mode 100644 data_structures/stk/stack.h rename data_structures/{stk => }/student.txt (100%) rename data_structures/{queue => }/test_queue.cpp (100%) rename data_structures/{stk => }/test_stack.cpp (100%) rename data_structures/{stk/main.cpp => test_stack_students.cpp} (100%) diff --git a/data_structures/CMakeLists.txt b/data_structures/CMakeLists.txt index fab3c5642..6c0555148 100644 --- a/data_structures/CMakeLists.txt +++ b/data_structures/CMakeLists.txt @@ -18,5 +18,3 @@ foreach( testsourcefile ${APP_SOURCES} ) endforeach( testsourcefile ${APP_SOURCES} ) add_subdirectory(cll) -add_subdirectory(queue) -add_subdirectory(stk) diff --git a/data_structures/queue.h b/data_structures/queue.h new file mode 100644 index 000000000..ed97a1e8d --- /dev/null +++ b/data_structures/queue.h @@ -0,0 +1,88 @@ +/* This class specifies the basic operation on a queue as a linked list */ +#ifndef DATA_STRUCTURES_QUEUE_QUEUE_H_ +#define DATA_STRUCTURES_QUEUE_QUEUE_H_ + +#include +#include + +/** Definition of the node */ +template +struct node { + Kind data; + node *next; +}; + +/** Definition of the queue class */ +template +class queue { + public: + /** Show queue */ + void display() { + node *current = queueFront; + std::cout << "Front --> "; + while (current != NULL) { + std::cout << current->data << " "; + current = current->next; + } + std::cout << std::endl; + std::cout << "Size of queue: " << size << std::endl; + }; + + /** Default constructor*/ + queue() { + queueFront = NULL; + queueRear = NULL; + size = 0; + }; + + /** Destructor */ + ~queue(){}; + + /** Determine whether the queue is empty */ + bool isEmptyQueue() { return (queueFront == NULL); }; + + /** Add new item to the queue */ + void enQueue(Kind item) { + node *newNode; + newNode = new node; + newNode->data = item; + newNode->next = NULL; + if (queueFront == NULL) { + queueFront = newNode; + queueRear = newNode; + } else { + queueRear->next = newNode; + queueRear = queueRear->next; + } + size++; + }; + + /** Return the first element of the queue */ + Kind front() { + assert(queueFront != NULL); + return queueFront->data; + }; + + /** Remove the top element of the queue */ + void deQueue() { + node *temp; + if (!isEmptyQueue()) { + temp = queueFront; + queueFront = queueFront->next; + delete temp; + size--; + } else { + std::cout << "Queue is empty !" << std::endl; + } + }; + + /** Clear queue */ + void clear() { queueFront = NULL; }; + + private: + node *queueFront; /**< Pointer to the front of the queue */ + node *queueRear; /**< Pointer to the rear of the queue */ + int size; +}; + +#endif // DATA_STRUCTURES_QUEUE_QUEUE_H_ diff --git a/data_structures/queue/CMakeLists.txt b/data_structures/queue/CMakeLists.txt deleted file mode 100644 index 434d3bb45..000000000 --- a/data_structures/queue/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_library(libqueue OBJECT queue.h queue.cpp) -add_executable( test_queue - test_queue.cpp -) -target_link_libraries(test_queue PUBLIC libqueue) - -install(TARGETS test_queue DESTINATION "bin/data_structures") diff --git a/data_structures/queue/queue.cpp b/data_structures/queue/queue.cpp deleted file mode 100644 index 9d5f9b9df..000000000 --- a/data_structures/queue/queue.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "./queue.h" - -#include -#include - -/* Default constructor*/ -template -queue::queue() { - queueFront = NULL; - queueRear = NULL; - size = 0; -} - -/* Destructor */ -template -queue::~queue() {} - -/* Display for testing */ -template -void queue::display() { - node *current = queueFront; - std::cout << "Front --> "; - while (current != NULL) { - std::cout << current->data << " "; - current = current->next; - } - std::cout << std::endl; - std::cout << "Size of queue: " << size << std::endl; -} - -/* Determine whether the queue is empty */ -template -bool queue::isEmptyQueue() { - return (queueFront == NULL); -} - -/* Clear queue */ -template -void queue::clear() { - queueFront = NULL; -} - -/* Add new item to the queue */ -template -void queue::enQueue(Kind item) { - node *newNode; - newNode = new node; - newNode->data = item; - newNode->next = NULL; - if (queueFront == NULL) { - queueFront = newNode; - queueRear = newNode; - } else { - queueRear->next = newNode; - queueRear = queueRear->next; - } - size++; -} - -/* Return the top element of the queue */ -template -Kind queue::front() { - assert(queueFront != NULL); - return queueFront->data; -} - -/* Remove the element of the queue */ -template -void queue::deQueue() { - node *temp; - if (!isEmptyQueue()) { - temp = queueFront; - queueFront = queueFront->next; - delete temp; - size--; - } else { - std::cout << "Queue is empty !" << std::endl; - } -} - -#include -/** force instantiate to export the type class */ -template class queue; diff --git a/data_structures/queue/queue.h b/data_structures/queue/queue.h deleted file mode 100644 index d55ee3864..000000000 --- a/data_structures/queue/queue.h +++ /dev/null @@ -1,31 +0,0 @@ -/* This class specifies the basic operation on a queue as a linked list */ -#ifndef DATA_STRUCTURES_QUEUE_QUEUE_H_ -#define DATA_STRUCTURES_QUEUE_QUEUE_H_ - -/** Definition of the node */ -template -struct node { - Kind data; - node *next; -}; - -/** Definition of the queue class */ -template -class queue { - public: - void display(); /**< Show queue */ - queue(); /**< Default constructor*/ - ~queue(); /**< Destructor */ - bool isEmptyQueue(); /**< Determine whether the queue is empty */ - void enQueue(Kind item); /**< Add new item to the queue */ - Kind front(); /**< Return the first element of the queue */ - void deQueue(); /**< Remove the top element of the queue */ - void clear(); - - private: - node *queueFront; /**< Pointer to the front of the queue */ - node *queueRear; /**< Pointer to the rear of the queue */ - int size; -}; - -#endif // DATA_STRUCTURES_QUEUE_QUEUE_H_ diff --git a/data_structures/stack.h b/data_structures/stack.h new file mode 100644 index 000000000..7b50e1f67 --- /dev/null +++ b/data_structures/stack.h @@ -0,0 +1,111 @@ +/* This class specifies the basic operation on a stack as a linked list */ +#ifndef DATA_STRUCTURES_STK_STACK_H_ +#define DATA_STRUCTURES_STK_STACK_H_ + +#include +#include + +/* Definition of the node */ +template +struct node { + Type data; + node *next; +}; + +/* Definition of the stack class */ +template +class stack { + public: + /** Show stack */ + void display() { + node *current = stackTop; + std::cout << "Top --> "; + while (current != NULL) { + std::cout << current->data << " "; + current = current->next; + } + std::cout << std::endl; + std::cout << "Size of stack: " << size << std::endl; + }; + + /** Default constructor*/ + stack() { + stackTop = NULL; + size = 0; + }; + + /** Destructor */ + ~stack(){}; + + /** Determine whether the stack is empty */ + bool isEmptyStack() { return (stackTop == NULL); }; + + /** Add new item to the stack */ + void push(Type item) { + node *newNode; + newNode = new node; + newNode->data = item; + newNode->next = stackTop; + stackTop = newNode; + size++; + }; + + /** Return the top element of the stack */ + Type top() { + assert(stackTop != NULL); + return stackTop->data; + }; + + /** Remove the top element of the stack */ + void pop() { + node *temp; + if (!isEmptyStack()) { + temp = stackTop; + stackTop = stackTop->next; + delete temp; + size--; + } else { + std::cout << "Stack is empty !" << std::endl; + } + }; + + /** Clear stack */ + void clear() { stackTop = NULL; }; + + /** Overload "=" the assignment operator */ + stack &operator=(const stack &otherStack) { + node *newNode, *current, *last; + + /* If stack is no empty, make it empty */ + if (stackTop != NULL) { + stackTop = NULL; + } + if (otherStack.stackTop == NULL) { + stackTop = NULL; + } else { + current = otherStack.stackTop; + stackTop = new node; + stackTop->data = current->data; + stackTop->next = NULL; + last = stackTop; + current = current->next; + /* Copy the remaining stack */ + while (current != NULL) { + newNode = new node; + newNode->data = current->data; + newNode->next = NULL; + last->next = newNode; + last = newNode; + current = current->next; + } + } + size = otherStack.size; + return *this; + }; + + private: + node *stackTop; /**< Pointer to the stack */ + int size; +}; + +#endif // DATA_STRUCTURES_STK_STACK_H_ diff --git a/data_structures/stk/CMakeLists.txt b/data_structures/stk/CMakeLists.txt deleted file mode 100644 index 30149ec06..000000000 --- a/data_structures/stk/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -add_library(libstack OBJECT stack.h stack.cpp) -add_executable( stack - main.cpp -) -target_link_libraries(stack PUBLIC libstack) -# set_target_properties(stack PROPERTIES LINKER_LANGUAGE CXX) - -add_executable( test_stack - test_stack.cpp -) -target_link_libraries(test_stack PUBLIC libstack) - -install(TARGETS stack DESTINATION "bin/data_structures") -install(TARGETS test_stack DESTINATION "bin/data_structures") -install(FILES students.txt DESTINATION "bin/data_structures") diff --git a/data_structures/stk/stack.cpp b/data_structures/stk/stack.cpp deleted file mode 100644 index 23aa3c05a..000000000 --- a/data_structures/stk/stack.cpp +++ /dev/null @@ -1,109 +0,0 @@ -#include "./stack.h" - -#include -#include - -/* Default constructor*/ -template -stack::stack() { - stackTop = NULL; - size = 0; -} - -/* Destructor */ -template -stack::~stack() {} - -/* Display for testing */ -template -void stack::display() { - node *current = stackTop; - std::cout << "Top --> "; - while (current != NULL) { - std::cout << current->data << " "; - current = current->next; - } - std::cout << std::endl; - std::cout << "Size of stack: " << size << std::endl; -} - -/* Determine whether the stack is empty */ -template -bool stack::isEmptyStack() { - return (stackTop == NULL); -} - -/* Clear stack */ -template -void stack::clear() { - stackTop = NULL; -} - -/* Add new item to the stack */ -template -void stack::push(Type item) { - node *newNode; - newNode = new node; - newNode->data = item; - newNode->next = stackTop; - stackTop = newNode; - size++; -} - -/* Return the top element of the stack */ -template -Type stack::top() { - assert(stackTop != NULL); - return stackTop->data; -} - -/* Remove the top element of the stack */ -template -void stack::pop() { - node *temp; - if (!isEmptyStack()) { - temp = stackTop; - stackTop = stackTop->next; - delete temp; - size--; - } else { - std::cout << "Stack is empty !" << std::endl; - } -} - -/* Operator "=" */ -template -stack &stack::operator=(const stack &otherStack) { - node *newNode, *current, *last; - - /* If stack is no empty, make it empty */ - if (stackTop != NULL) { - stackTop = NULL; - } - if (otherStack.stackTop == NULL) { - stackTop = NULL; - } else { - current = otherStack.stackTop; - stackTop = new node; - stackTop->data = current->data; - stackTop->next = NULL; - last = stackTop; - current = current->next; - /* Copy the remaining stack */ - while (current != NULL) { - newNode = new node; - newNode->data = current->data; - newNode->next = NULL; - last->next = newNode; - last = newNode; - current = current->next; - } - } - size = otherStack.size; - return *this; -} - -#include -/** force instantiate to export the type class */ -template class stack; -template class stack; diff --git a/data_structures/stk/stack.h b/data_structures/stk/stack.h deleted file mode 100644 index e038440a1..000000000 --- a/data_structures/stk/stack.h +++ /dev/null @@ -1,32 +0,0 @@ -/* This class specifies the basic operation on a stack as a linked list */ -#ifndef DATA_STRUCTURES_STK_STACK_H_ -#define DATA_STRUCTURES_STK_STACK_H_ - -/* Definition of the node */ -template -struct node { - Type data; - node *next; -}; - -/* Definition of the stack class */ -template -class stack { - public: - void display(); /* Show stack */ - stack(); /* Default constructor*/ - ~stack(); /* Destructor */ - bool isEmptyStack(); /* Determine whether the stack is empty */ - void push(Type item); /* Add new item to the stack */ - Type top(); /* Return the top element of the stack */ - void pop(); /* Remove the top element of the stack */ - void clear(); - - stack &operator=(const stack &otherStack); - // Overload "=" the assignment operator. - private: - node *stackTop; /* Pointer to the stack */ - int size; -}; - -#endif // DATA_STRUCTURES_STK_STACK_H_ diff --git a/data_structures/stk/student.txt b/data_structures/student.txt similarity index 100% rename from data_structures/stk/student.txt rename to data_structures/student.txt diff --git a/data_structures/queue/test_queue.cpp b/data_structures/test_queue.cpp similarity index 100% rename from data_structures/queue/test_queue.cpp rename to data_structures/test_queue.cpp diff --git a/data_structures/stk/test_stack.cpp b/data_structures/test_stack.cpp similarity index 100% rename from data_structures/stk/test_stack.cpp rename to data_structures/test_stack.cpp diff --git a/data_structures/stk/main.cpp b/data_structures/test_stack_students.cpp similarity index 100% rename from data_structures/stk/main.cpp rename to data_structures/test_stack_students.cpp From d97f7c15f6c1709631102f0b97e4fab7c52cf9b0 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sat, 6 Jun 2020 16:57:19 +0000 Subject: [PATCH 09/12] updating DIRECTORY.md --- DIRECTORY.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index bdfa2c951..31093341a 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -25,21 +25,17 @@ * [Linkedlist Implentation Usingarray](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/linkedlist_implentation_usingarray.cpp) * [List Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/list_array.cpp) * [Morrisinorder](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/morrisinorder.cpp) - * Queue - * [Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue/queue.cpp) - * [Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue/queue.h) - * [Test Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue/test_queue.cpp) + * [Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue.h) * [Queue Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue_using_array.cpp) * [Queue Using Array2](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue_using_array2.cpp) * [Queue Using Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue_using_linked_list.cpp) * [Queue Using Linkedlist](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/queue_using_linkedlist.cpp) + * [Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stack.h) * [Stack Using Array](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stack_using_array.cpp) * [Stack Using Linked List](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stack_using_linked_list.cpp) - * Stk - * [Main](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stk/main.cpp) - * [Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stk/stack.cpp) - * [Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stk/stack.h) - * [Test Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/stk/test_stack.cpp) + * [Test Queue](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/test_queue.cpp) + * [Test Stack](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/test_stack.cpp) + * [Test Stack Students](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/test_stack_students.cpp) * [Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/tree.cpp) * [Trie Modern](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/trie_modern.cpp) * [Trie Tree](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/data_structures/trie_tree.cpp) From b3f0b75a08106a107f49f259451e2940fd1bfa9b Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 13:02:36 -0400 Subject: [PATCH 10/12] remove semicolons after functions in a class Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- data_structures/queue.h | 16 ++++++++-------- data_structures/stack.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/data_structures/queue.h b/data_structures/queue.h index ed97a1e8d..dd53da7d0 100644 --- a/data_structures/queue.h +++ b/data_structures/queue.h @@ -26,20 +26,20 @@ class queue { } std::cout << std::endl; std::cout << "Size of queue: " << size << std::endl; - }; + } /** Default constructor*/ queue() { queueFront = NULL; queueRear = NULL; size = 0; - }; + } /** Destructor */ - ~queue(){}; + ~queue() {} /** Determine whether the queue is empty */ - bool isEmptyQueue() { return (queueFront == NULL); }; + bool isEmptyQueue() { return (queueFront == NULL); } /** Add new item to the queue */ void enQueue(Kind item) { @@ -55,13 +55,13 @@ class queue { queueRear = queueRear->next; } size++; - }; + } /** Return the first element of the queue */ Kind front() { assert(queueFront != NULL); return queueFront->data; - }; + } /** Remove the top element of the queue */ void deQueue() { @@ -74,10 +74,10 @@ class queue { } else { std::cout << "Queue is empty !" << std::endl; } - }; + } /** Clear queue */ - void clear() { queueFront = NULL; }; + void clear() { queueFront = NULL; } private: node *queueFront; /**< Pointer to the front of the queue */ diff --git a/data_structures/stack.h b/data_structures/stack.h index 7b50e1f67..8278a3d00 100644 --- a/data_structures/stack.h +++ b/data_structures/stack.h @@ -26,16 +26,16 @@ class stack { } std::cout << std::endl; std::cout << "Size of stack: " << size << std::endl; - }; + } /** Default constructor*/ stack() { stackTop = NULL; size = 0; - }; + } /** Destructor */ - ~stack(){}; + ~stack() {} /** Determine whether the stack is empty */ bool isEmptyStack() { return (stackTop == NULL); }; @@ -48,13 +48,13 @@ class stack { newNode->next = stackTop; stackTop = newNode; size++; - }; + } /** Return the top element of the stack */ Type top() { assert(stackTop != NULL); return stackTop->data; - }; + } /** Remove the top element of the stack */ void pop() { @@ -67,10 +67,10 @@ class stack { } else { std::cout << "Stack is empty !" << std::endl; } - }; + } /** Clear stack */ - void clear() { stackTop = NULL; }; + void clear() { stackTop = NULL; } /** Overload "=" the assignment operator */ stack &operator=(const stack &otherStack) { @@ -101,7 +101,7 @@ class stack { } size = otherStack.size; return *this; - }; + } private: node *stackTop; /**< Pointer to the stack */ From 8a2bef9c20946bc70f8a97c76b837426adfbb903 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 13:36:04 -0400 Subject: [PATCH 11/12] cpplint header guard style Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- data_structures/queue.h | 6 +++--- data_structures/stack.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/data_structures/queue.h b/data_structures/queue.h index dd53da7d0..3cb551741 100644 --- a/data_structures/queue.h +++ b/data_structures/queue.h @@ -1,6 +1,6 @@ /* This class specifies the basic operation on a queue as a linked list */ -#ifndef DATA_STRUCTURES_QUEUE_QUEUE_H_ -#define DATA_STRUCTURES_QUEUE_QUEUE_H_ +#ifndef DATA_STRUCTURES_QUEUE_H_ +#define DATA_STRUCTURES_QUEUE_H_ #include #include @@ -85,4 +85,4 @@ class queue { int size; }; -#endif // DATA_STRUCTURES_QUEUE_QUEUE_H_ +#endif // DATA_STRUCTURES_QUEUE_H_ diff --git a/data_structures/stack.h b/data_structures/stack.h index 8278a3d00..a27d2462b 100644 --- a/data_structures/stack.h +++ b/data_structures/stack.h @@ -1,6 +1,6 @@ /* This class specifies the basic operation on a stack as a linked list */ -#ifndef DATA_STRUCTURES_STK_STACK_H_ -#define DATA_STRUCTURES_STK_STACK_H_ +#ifndef DATA_STRUCTURES_STACK_H_ +#define DATA_STRUCTURES_STACK_H_ #include #include @@ -108,4 +108,4 @@ class stack { int size; }; -#endif // DATA_STRUCTURES_STK_STACK_H_ +#endif // DATA_STRUCTURES_STACK_H_ From 869245dff526feaa588b65799570648b76a54518 Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Sat, 6 Jun 2020 13:37:55 -0400 Subject: [PATCH 12/12] remove semilon Signed-off-by: Krishna Vedala <7001608+kvedala@users.noreply.github.com> --- data_structures/stack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/stack.h b/data_structures/stack.h index a27d2462b..f4b8992e7 100644 --- a/data_structures/stack.h +++ b/data_structures/stack.h @@ -38,7 +38,7 @@ class stack { ~stack() {} /** Determine whether the stack is empty */ - bool isEmptyStack() { return (stackTop == NULL); }; + bool isEmptyStack() { return (stackTop == NULL); } /** Add new item to the stack */ void push(Type item) {