diff --git a/Project3/Project3.cpp b/Project3/Project3.cpp new file mode 100644 index 0000000..622e10c --- /dev/null +++ b/Project3/Project3.cpp @@ -0,0 +1,92 @@ +//Corey Williams +//COP3530 01Z +//Project 4 + +/*Write a C++ or Java application that creates a linked list of Circle objects/structures (i.e., class must be created). +The application can use the "IntSLLNode" and "IntSLList" classes (pp. 78 - 83) as a guide. +The application must provide the following features. + +Allow insertion of multiple "Circle" objects/structures. +The Circle contains a "radius" data member. +The Circle also uses functions/methods "setRadius", "getRadius" and calculateArea (returns a double data type). +Invoke a method/function "DisplayAllElements" (i.e., must be written, traversal required; refer to "isInList" method, pg. 80) that receives +a "reference/pointer" formal parameter. This formal parameter specifies the "head" of the list. +The function/method must display all elements "position", "radius" , and "area" +*/ + +#define _USE_MATH_DEFINES + +#include +#include + +using namespace std; + +class Circle { +private: + double radius; + +public: + Circle(double r) { + radius = r; + } + + double getRadius() { + return radius; + } + + void setRadius(double r) { + radius = r; + } + + double calculateArea() { + return M_PI * radius * radius; + } +}; + +class CirSLLNode { +public: + CirSLLNode() { + next = 0; + } + CirSLLNode(int el, CirSLLNode* ptr = 0) { + info = el; next = ptr; + } + int info; + CirSLLNode* next; +}; + +class CirSLList { +public: + CirSLList() { + head = tail = 0; + } + ~CirSLList(); + int isEmpty() { + return head == 0; + } + void addNode(Circle); + +private: + CirSLLNode* head, * tail; +}; + +int main() +{ + double r; + string userResp; + + do { + cout << "Enter radius for first circle: "; + cin >> r; + + Circle tmpCir(r); + //add tmpCir to linked list + + cout << "Would you like to add another circle? Y/N: "; + cin >> userResp; + + } while (userResp != "N" and userResp != "n"); + + +} + diff --git a/Project3/Project3.sln b/Project3/Project3.sln new file mode 100644 index 0000000..635cb79 --- /dev/null +++ b/Project3/Project3.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33801.468 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project3", "Project3.vcxproj", "{8D2214F5-A52E-4E45-A765-0C785D99B33F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8D2214F5-A52E-4E45-A765-0C785D99B33F}.Debug|x64.ActiveCfg = Debug|x64 + {8D2214F5-A52E-4E45-A765-0C785D99B33F}.Debug|x64.Build.0 = Debug|x64 + {8D2214F5-A52E-4E45-A765-0C785D99B33F}.Debug|x86.ActiveCfg = Debug|Win32 + {8D2214F5-A52E-4E45-A765-0C785D99B33F}.Debug|x86.Build.0 = Debug|Win32 + {8D2214F5-A52E-4E45-A765-0C785D99B33F}.Release|x64.ActiveCfg = Release|x64 + {8D2214F5-A52E-4E45-A765-0C785D99B33F}.Release|x64.Build.0 = Release|x64 + {8D2214F5-A52E-4E45-A765-0C785D99B33F}.Release|x86.ActiveCfg = Release|Win32 + {8D2214F5-A52E-4E45-A765-0C785D99B33F}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {BAED36CB-181C-4D78-B2ED-CAE7DB7B6B89} + EndGlobalSection +EndGlobal diff --git a/Project3/Project3.vcxproj b/Project3/Project3.vcxproj new file mode 100644 index 0000000..2b394bc --- /dev/null +++ b/Project3/Project3.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {8d2214f5-a52e-4e45-a765-0c785d99b33f} + Project3 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/Project3/Project3.vcxproj.filters b/Project3/Project3.vcxproj.filters new file mode 100644 index 0000000..cf84f06 --- /dev/null +++ b/Project3/Project3.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/Project3/intSLList.cpp b/Project3/intSLList.cpp new file mode 100644 index 0000000..38bffe5 --- /dev/null +++ b/Project3/intSLList.cpp @@ -0,0 +1,90 @@ +//************************ intSLList.cpp ************************** + +#include +#include "intSLList.h" + +IntSLList::~IntSLList() { + for (IntSLLNode *p; !isEmpty(); ) { + p = head->next; + delete head; + head = p; + } +} + +void IntSLList::addToHead(int el) { + head = new IntSLLNode(el,head); + if (tail == 0) + tail = head; +} + +void IntSLList::addToTail(int el) { + if (tail != 0) { // if list not empty; + tail->next = new IntSLLNode(el); + tail = tail->next; + } + else head = tail = new IntSLLNode(el); +} + +int IntSLList::deleteFromHead() { + int el = head->info; + IntSLLNode *tmp = head; + if (head == tail) // if only one node on the list; + head = tail = 0; + else head = head->next; + delete tmp; + return el; +} + +int IntSLList::deleteFromTail() { + int el = tail->info; + if (head == tail) { // if only one node on the list; + delete head; + head = tail = 0; + } + else { // if more than one node in the list, + IntSLLNode *tmp; // find the predecessor of tail; + for (tmp = head; tmp->next != tail; tmp = tmp->next); + delete tail; + tail = tmp; // the predecessor of tail becomes tail; + tail->next = 0; + } + return el; +} + +void IntSLList::deleteNode(int el) { + if (head != 0) // if non-empty list; + if (head == tail && el == head->info) { // if only one + delete head; // node on the list; + head = tail = 0; + } + else if (el == head->info) { // if more than one node on the list + IntSLLNode *tmp = head; + head = head->next; + delete tmp; // and old head is deleted; + } + else { // if more than one node in the list + IntSLLNode *pred, *tmp; + for (pred = head, tmp = head->next; // and a non-head node + tmp != 0 && !(tmp->info == el);// is deleted; + pred = pred->next, tmp = tmp->next); + if (tmp != 0) { + pred->next = tmp->next; + if (tmp == tail) + tail = pred; + delete tmp; + } + } +} + +bool IntSLList::isInList(int el) const { + IntSLLNode *tmp; + for (tmp = head; tmp != 0 && !(tmp->info == el); tmp = tmp->next); + return tmp != 0; +} + +void IntSLList::printAll() const { + for (IntSLLNode *tmp = head; tmp != 0; tmp = tmp->next) + cout << tmp->info << " "; + cout << endl; +} + diff --git a/Project3/intSLList.h b/Project3/intSLList.h new file mode 100644 index 0000000..46e1a63 --- /dev/null +++ b/Project3/intSLList.h @@ -0,0 +1,39 @@ +//************************ intSLList.h ************************** +// singly-linked list class to store integers + +#ifndef INT_LINKED_LIST +#define INT_LINKED_LIST + +class IntSLLNode { +public: + IntSLLNode() { + next = 0; + } + IntSLLNode(int el, IntSLLNode *ptr = 0) { + info = el; next = ptr; + } + int info; + IntSLLNode *next; +}; + +class IntSLList { +public: + IntSLList() { + head = tail = 0; + } + ~IntSLList(); + int isEmpty() { + return head == 0; + } + void addToHead(int); + void addToTail(int); + int deleteFromHead(); // delete the head and return its info; + int deleteFromTail(); // delete the tail and return its info; + void deleteNode(int); + bool isInList(int) const; + void printAll() const; +private: + IntSLLNode *head, *tail; +}; + +#endif diff --git a/Project4/Project4.cpp b/Project4/Project4.cpp new file mode 100644 index 0000000..ba3ddce --- /dev/null +++ b/Project4/Project4.cpp @@ -0,0 +1,41 @@ +//Corey Williams +//COP3530 01Z +//Project 4 + +/*Write a C++ or Java application that creates a linked list of Circle objects/structures (i.e., class must be created). +The application can use the "IntSLLNode" and "IntSLList" classes (pp. 78 - 83) as a guide. +The application must provide the following features. + +Allow insertion of multiple "Circle" objects/structures. +The Circle contains a "radius" data member. +The Circle also uses functions/methods "setRadius", "getRadius" and calculateArea (returns a double data type). +Invoke a method/function "DisplayAllElements" (i.e., must be written, traversal required; refer to "isInList" method, pg. 80) that receives +a "reference/pointer" formal parameter. This formal parameter specifies the "head" of the list. +The function/method must display all elements "position", "radius" , and "area" +*/ + +#include +#include "cirSLList.h" +#include "circle.h" + +using namespace std; + +int main() +{ + double r; + string userResp; + cirSLList CircleList; + + do { + cout << "Enter radius for circle: "; + cin >> r; + + CircleList.addToTail(r); + + cout << "Would you like to add another circle? Y/N: "; + cin >> userResp; + + } while (userResp != "N" and userResp != "n"); + + CircleList.displayAllElements(); +} \ No newline at end of file diff --git a/Project4/Project4.sln b/Project4/Project4.sln new file mode 100644 index 0000000..eae0e16 --- /dev/null +++ b/Project4/Project4.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33801.468 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project4", "Project4.vcxproj", "{1567CA04-7F5A-485C-BF7A-7A499ECD2102}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Debug|x64.ActiveCfg = Debug|x64 + {1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Debug|x64.Build.0 = Debug|x64 + {1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Debug|x86.ActiveCfg = Debug|Win32 + {1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Debug|x86.Build.0 = Debug|Win32 + {1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Release|x64.ActiveCfg = Release|x64 + {1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Release|x64.Build.0 = Release|x64 + {1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Release|x86.ActiveCfg = Release|Win32 + {1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {01E804E5-D748-4033-8FDF-639ED6D999A9} + EndGlobalSection +EndGlobal diff --git a/Project4/Project4.vcxproj b/Project4/Project4.vcxproj new file mode 100644 index 0000000..da9bea5 --- /dev/null +++ b/Project4/Project4.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {1567ca04-7f5a-485c-bf7a-7a499ecd2102} + Project4 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/Project4/Project4.vcxproj.filters b/Project4/Project4.vcxproj.filters new file mode 100644 index 0000000..b9747f2 --- /dev/null +++ b/Project4/Project4.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/Project4/cirSLList.cpp b/Project4/cirSLList.cpp new file mode 100644 index 0000000..17a4775 --- /dev/null +++ b/Project4/cirSLList.cpp @@ -0,0 +1,35 @@ +//************************ cirSLList.cpp ************************** + +#include +#include "cirSLList.h" +#include "circle.h" + +using namespace std; + +cirSLList::~cirSLList() { + for (cirSLLNode *p; !isEmpty(); ) { + p = head->next; + delete head; + head = p; + } +} + +void cirSLList::addToTail(double el) { + if (tail != 0) { // if list not empty; + tail->next = new cirSLLNode(el); + tail = tail->next; + } + else head = tail = new cirSLLNode(el); +} + +void cirSLList::displayAllElements() { + int i = 1; + for (cirSLLNode* tmp = head; tmp != 0; tmp = tmp->next) { + cout << i << ". "; + cout << "Radius: " << tmp->info.getRadius() << " - "; + cout << "Area: " << tmp->info.calculateArea() << endl; + i++; + } + cout << endl; +} + diff --git a/Project4/cirSLList.h b/Project4/cirSLList.h new file mode 100644 index 0000000..57fad3b --- /dev/null +++ b/Project4/cirSLList.h @@ -0,0 +1,34 @@ +//************************ cirSLList.h ************************** +// singly-linked list class to store integers + +#ifndef INT_LINKED_LIST +#define INT_LINKED_LIST + +#include "circle.h" + +class cirSLLNode { +public: + Circle info; + cirSLLNode(double el, cirSLLNode *ptr = 0) { + info.setRadius(el); next = ptr; + } + cirSLLNode *next; +}; + +class cirSLList { +public: + cirSLList() { + head = tail = NULL; + } + ~cirSLList(); + int isEmpty() { + return head == 0; + } + void addToTail(double); + bool isInList(Circle) const; + void displayAllElements(); +private: + cirSLLNode *head, *tail; +}; + +#endif diff --git a/Project4/circle.cpp b/Project4/circle.cpp new file mode 100644 index 0000000..8b710e6 --- /dev/null +++ b/Project4/circle.cpp @@ -0,0 +1,29 @@ +#define _USE_MATH_DEFINES + +#include + +class Circle { +private: + double radius; + +public: + Circle() { + radius = 0; + } + + Circle(double r) { + radius = r; + } + + double getRadius() { + return radius; + } + + void setRadius(double r) { + radius = r; + } + + double calculateArea() { + return M_PI * radius * radius; + } +}; \ No newline at end of file diff --git a/Project4/circle.h b/Project4/circle.h new file mode 100644 index 0000000..723635b --- /dev/null +++ b/Project4/circle.h @@ -0,0 +1,34 @@ +#ifndef CIRCLE_HEADER +#define CIRCLE_HEADER + +#define _USE_MATH_DEFINES + +#include + +class Circle { +private: + double radius; + +public: + Circle() { + radius = 0; + } + + Circle(double r) { + radius = r; + } + + double getRadius() { + return radius; + } + + void setRadius(double r) { + radius = r; + } + + double calculateArea() { + return M_PI * radius * radius; + } +}; + +#endif \ No newline at end of file diff --git a/Project5/Project5.cpp b/Project5/Project5.cpp new file mode 100644 index 0000000..7e0fa18 --- /dev/null +++ b/Project5/Project5.cpp @@ -0,0 +1,108 @@ +// Corey Williams +// COP3530 01Z +//Project 5 + +//10. Write a member function to check whether two singly linked lists have the same contents + +#include +#include "intSLList.h" + +using namespace std; + +void testOutput(bool result, bool expResult) { + if (result == expResult) { cout << "TEST PASS"; } + else { cout << "TEST FAIL"; } + cout << " Expected: " << expResult << " | Actual : " << result << endl; +} + +int main() +{ + IntSLList listA; + IntSLList listB; + int arrA[5] = { 2, 24, -1, 88, 3 }; + + + //Test 1: Test two linked lists that are equivalent elements and same length - Expected result is TRUE (1) + //Loads arrA into both linked lists + for (int i = 0; i < 5; i++) { + listA.addToTail(arrA[i]); + listB.addToTail(arrA[i]); + } + + testOutput(listA.isEqual(listB.getHeadElement()), true); + listA.printAll(); + listB.printAll(); + + //Clear listB for new test + while (!listB.isEmpty()) { listB.deleteFromTail(); } + + + //Test 2: Test two linked lists that are unequal but the same length - Expected result is FALSE (0) + int arrB[5] = { 2, 24, -1, 88, 5 }; + for (int i = 0; i < 5; i++) { + listB.addToTail(arrB[i]); + } + + testOutput(listA.isEqual(listB.getHeadElement()), false); + listA.printAll(); + listB.printAll(); + + //Clear listB for new test + while (!listB.isEmpty()) { listB.deleteFromTail(); } + + + //Test 3: Test two linked lists that are unequal and the second list is longer - Expected result is FALSE (0) + int arrC[8] = { 1, 2, 3, 4, 5, 6, 7, 8 }; + for (int i = 0; i < sizeof(arrC)/sizeof(arrC[0]); i++) { + listB.addToTail(arrC[i]); + } + + testOutput(listA.isEqual(listB.getHeadElement()), false); + listA.printAll(); + listB.printAll(); + + //Clear listB for new test + while (!listB.isEmpty()) { listB.deleteFromTail(); } + + + //Test 4: Test two linked lists that are unequal and the second list is shorter - Expected result is FALSE (0) + int arrD[3] = { 1, 2, 3 }; + for (int i = 0; i < sizeof(arrD) / sizeof(arrD[0]); i++) { + listB.addToTail(arrD[i]); + } + + testOutput(listA.isEqual(listB.getHeadElement()), false); + listA.printAll(); + listB.printAll(); + + //Clear listB for new test + while (!listB.isEmpty()) { listB.deleteFromTail(); } + + + //Test 5: Test two linked lists where the first list is a subset of the second - Expected result is FALSE (0) + int arrE[8] = { 2, 24, -1, 88, 3, 6, 7, 8 }; + for (int i = 0; i < sizeof(arrE) / sizeof(arrE[0]); i++) { + listB.addToTail(arrE[i]); + } + + testOutput(listA.isEqual(listB.getHeadElement()), false); + listA.printAll(); + listB.printAll(); + + //Clear listB for new test + while (!listB.isEmpty()) { listB.deleteFromTail(); } + + + //Test 6: Test two linked lists where the second list is a subset of the first - Expected result is FALSE (0) + int arrF[4] = { 2, 24, -1, 88 }; + for (int i = 0; i < sizeof(arrF) / sizeof(arrF[0]); i++) { + listB.addToTail(arrF[i]); + } + + testOutput(listA.isEqual(listB.getHeadElement()), false); + listA.printAll(); + listB.printAll(); + + //Clear listB for new test + while (!listB.isEmpty()) { listB.deleteFromTail(); } +} \ No newline at end of file diff --git a/Project5/Project5.sln b/Project5/Project5.sln new file mode 100644 index 0000000..5a70e74 --- /dev/null +++ b/Project5/Project5.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33801.468 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project5", "Project5.vcxproj", "{55494E87-AC76-4675-B4B1-E3752AEE567E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {55494E87-AC76-4675-B4B1-E3752AEE567E}.Debug|x64.ActiveCfg = Debug|x64 + {55494E87-AC76-4675-B4B1-E3752AEE567E}.Debug|x64.Build.0 = Debug|x64 + {55494E87-AC76-4675-B4B1-E3752AEE567E}.Debug|x86.ActiveCfg = Debug|Win32 + {55494E87-AC76-4675-B4B1-E3752AEE567E}.Debug|x86.Build.0 = Debug|Win32 + {55494E87-AC76-4675-B4B1-E3752AEE567E}.Release|x64.ActiveCfg = Release|x64 + {55494E87-AC76-4675-B4B1-E3752AEE567E}.Release|x64.Build.0 = Release|x64 + {55494E87-AC76-4675-B4B1-E3752AEE567E}.Release|x86.ActiveCfg = Release|Win32 + {55494E87-AC76-4675-B4B1-E3752AEE567E}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7BA3C2DE-C47D-4833-8BE7-E256AF5B6D42} + EndGlobalSection +EndGlobal diff --git a/Project5/Project5.vcxproj b/Project5/Project5.vcxproj new file mode 100644 index 0000000..36c32e4 --- /dev/null +++ b/Project5/Project5.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {55494e87-ac76-4675-b4b1-e3752aee567e} + Project5 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/Project5/Project5.vcxproj.filters b/Project5/Project5.vcxproj.filters new file mode 100644 index 0000000..7126992 --- /dev/null +++ b/Project5/Project5.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/Project5/intSLList.cpp b/Project5/intSLList.cpp new file mode 100644 index 0000000..e816b46 --- /dev/null +++ b/Project5/intSLList.cpp @@ -0,0 +1,119 @@ +//************************ intSLList.cpp ************************** + +#include +#include "intSLList.h" + +using namespace std; + +IntSLList::~IntSLList() { + for (IntSLLNode *p; !isEmpty(); ) { + p = head->next; + delete head; + head = p; + } +} + +void IntSLList::addToHead(int el) { + head = new IntSLLNode(el,head); + if (tail == 0) + tail = head; +} + +void IntSLList::addToTail(int el) { + if (tail != 0) { // if list not empty; + tail->next = new IntSLLNode(el); + tail = tail->next; + } + else head = tail = new IntSLLNode(el); +} + +int IntSLList::deleteFromHead() { + int el = head->info; + IntSLLNode *tmp = head; + if (head == tail) // if only one node on the list; + head = tail = 0; + else head = head->next; + delete tmp; + return el; +} + +int IntSLList::deleteFromTail() { + int el = tail->info; + if (head == tail) { // if only one node on the list; + delete head; + head = tail = 0; + } + else { // if more than one node in the list, + IntSLLNode *tmp; // find the predecessor of tail; + for (tmp = head; tmp->next != tail; tmp = tmp->next); + delete tail; + tail = tmp; // the predecessor of tail becomes tail; + tail->next = 0; + } + return el; +} + +void IntSLList::deleteNode(int el) { + if (head != 0) // if non-empty list; + if (head == tail && el == head->info) { // if only one + delete head; // node on the list; + head = tail = 0; + } + else if (el == head->info) { // if more than one node on the list + IntSLLNode *tmp = head; + head = head->next; + delete tmp; // and old head is deleted; + } + else { // if more than one node in the list + IntSLLNode *pred, *tmp; + for (pred = head, tmp = head->next; // and a non-head node + tmp != 0 && !(tmp->info == el);// is deleted; + pred = pred->next, tmp = tmp->next); + if (tmp != 0) { + pred->next = tmp->next; + if (tmp == tail) + tail = pred; + delete tmp; + } + } +} + +bool IntSLList::isInList(int el) const { + IntSLLNode *tmp; + for (tmp = head; tmp != 0 && !(tmp->info == el); tmp = tmp->next); + return tmp != 0; +} + +void IntSLList::printAll() const { + for (IntSLLNode *tmp = head; tmp != 0; tmp = tmp->next) + cout << tmp->info << " "; + cout << endl; +} + +IntSLLNode* IntSLList::getHeadElement() { + return head; +} + +//compares existing LL instance to a second LL instance passed in by its head node. +bool IntSLList::isEqual(IntSLLNode *comp) { + + int i = 0, j = 0; + + //Test that both lists are of the same length + for (IntSLLNode* countA = head; countA != 0; countA = countA->next) { i++; } + for (IntSLLNode* countComp = comp; countComp != 0; countComp = countComp->next) { j++; } + if (i != j) { return false; } + + //Tests that both lists have the same elements + for (IntSLLNode *listA = head; listA != 0 && comp != 0; listA = listA->next) { + if (listA->info == comp->info && comp != 0 && listA != 0) { + comp = comp->next; + continue; + } + return false; + } + return true; +} + + + diff --git a/Project5/intSLList.h b/Project5/intSLList.h new file mode 100644 index 0000000..31af659 --- /dev/null +++ b/Project5/intSLList.h @@ -0,0 +1,41 @@ +//************************ intSLList.h ************************** +// singly-linked list class to store integers + +#ifndef INT_LINKED_LIST +#define INT_LINKED_LIST + +class IntSLLNode { +public: + IntSLLNode() { + next = 0; + } + IntSLLNode(int el, IntSLLNode *ptr = 0) { + info = el; next = ptr; + } + int info; + IntSLLNode *next; +}; + +class IntSLList { +public: + IntSLList() { + head = tail = 0; + } + ~IntSLList(); + int isEmpty() { + return head == 0; + } + void addToHead(int); + void addToTail(int); + int deleteFromHead(); // delete the head and return its info; + int deleteFromTail(); // delete the tail and return its info; + void deleteNode(int); + bool isInList(int) const; + void printAll() const; + bool isEqual(IntSLLNode* comp); + IntSLLNode* getHeadElement(); +private: + IntSLLNode *head, *tail; +}; + +#endif