aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CST 126/Homework 3/Homework 3.vcxproj37
-rw-r--r--CST 126/Homework 3/Homework 3.vcxproj.filters5
-rw-r--r--CST 126/Homework 3/main.cpp193
3 files changed, 215 insertions, 20 deletions
diff --git a/CST 126/Homework 3/Homework 3.vcxproj b/CST 126/Homework 3/Homework 3.vcxproj
index b1b2d80..4597b48 100644
--- a/CST 126/Homework 3/Homework 3.vcxproj
+++ b/CST 126/Homework 3/Homework 3.vcxproj
@@ -17,7 +17,6 @@
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
-
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
@@ -53,27 +52,24 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
-
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
- <ImportGroup Label="Shared" >
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
-
<PropertyGroup Label="UserMacros" />
-
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
@@ -130,9 +126,10 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
-
- <ItemGroup></ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="main.cpp" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project> \ No newline at end of file
diff --git a/CST 126/Homework 3/Homework 3.vcxproj.filters b/CST 126/Homework 3/Homework 3.vcxproj.filters
index a8a6563..ce0c35c 100644
--- a/CST 126/Homework 3/Homework 3.vcxproj.filters
+++ b/CST 126/Homework 3/Homework 3.vcxproj.filters
@@ -14,4 +14,9 @@
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="main.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
</Project> \ No newline at end of file
diff --git a/CST 126/Homework 3/main.cpp b/CST 126/Homework 3/main.cpp
new file mode 100644
index 0000000..73ebc4b
--- /dev/null
+++ b/CST 126/Homework 3/main.cpp
@@ -0,0 +1,193 @@
+#include <iostream>
+
+template <typename T>
+struct Node {
+ T data;
+ Node* next;
+
+ Node(T val) : data(val), next(nullptr) {}
+};
+
+template <typename T>
+class LinkedList {
+private:
+ Node<T>* head;
+
+public:
+ LinkedList() : head(nullptr) {}
+
+ void append(T val) {
+ Node<T>* newNode = new Node<T>(val);
+ if (!head) {
+ head = newNode;
+ return;
+ }
+ Node<T>* current = head;
+ while (current->next) {
+ current = current->next;
+ }
+ current->next = newNode;
+ }
+
+ void prepend(T val) {
+ Node<T>* newNode = new Node<T>(val);
+ newNode->next = head;
+ head = newNode;
+ }
+
+ void removeFirst() {
+ if (!head) return;
+ Node<T>* temp = head;
+ head = head->next;
+ delete temp;
+ }
+
+ void removeLast() {
+ if (!head) return;
+ if (!head->next) {
+ delete head;
+ head = nullptr;
+ return;
+ }
+ Node<T>* current = head;
+ while (current->next->next) {
+ current = current->next;
+ }
+ delete current->next;
+ current->next = nullptr;
+ }
+
+ void insertAfter(T key, T val) {
+ Node<T>* current = head;
+ while (current) {
+ if (current->data == key) {
+ Node<T>* newNode = new Node<T>(val);
+ newNode->next = current->next;
+ current->next = newNode;
+ return;
+ }
+ current = current->next;
+ }
+ }
+
+ void insertBefore(T key, T val) {
+ if (!head) return;
+ if (head->data == key) {
+ prepend(val);
+ return;
+ }
+ Node<T>* current = head;
+ while (current->next) {
+ if (current->next->data == key) {
+ Node<T>* newNode = new Node<T>(val);
+ newNode->next = current->next;
+ current->next = newNode;
+ return;
+ }
+ current = current->next;
+ }
+ }
+
+ void clear() {
+ while (head) {
+ Node<T>* temp = head;
+ head = head->next;
+ delete temp;
+ }
+ }
+
+ T extract() {
+ if (!head) {
+ std::cerr << "List is empty!" << std::endl;
+ exit(1);
+ }
+ T data = head->data;
+ removeFirst();
+ return data;
+ }
+
+ void printList() {
+ Node<T>* current = head;
+ while (current) {
+ std::cout << current->data << " ";
+ current = current->next;
+ }
+ std::cout << std::endl;
+ }
+
+ ~LinkedList() {
+ clear();
+ }
+};
+
+void runTests() {
+ std::cout << "Rainy Day Tests:\n";
+ LinkedList<int> list;
+
+ list.append(1);
+ list.append(2);
+ list.append(3);
+ std::cout << "Appended List: ";
+ list.printList();
+
+ list.prepend(0);
+ std::cout << "Prepended List: ";
+ list.printList();
+
+ list.removeFirst();
+ std::cout << "After RemoveFirst: ";
+ list.printList();
+
+ list.removeLast();
+ std::cout << "After RemoveLast: ";
+ list.printList();
+
+ list.insertAfter(2, 4);
+ std::cout << "After InsertAfter: ";
+ list.printList();
+
+ list.insertBefore(3, 5);
+ std::cout << "After InsertBefore: ";
+ list.printList();
+
+ list.clear();
+ std::cout << "After Clear: ";
+ list.printList();
+
+ std::cout << "\nSunny Day Tests:\n";
+
+ list.append(10);
+ list.append(20);
+ list.append(30);
+ std::cout << "Appended List: ";
+ list.printList();
+
+ list.prepend(5);
+ std::cout << "Prepended List: ";
+ list.printList();
+
+ list.removeFirst();
+ std::cout << "After RemoveFirst: ";
+ list.printList();
+
+ list.removeLast();
+ std::cout << "After RemoveLast: ";
+ list.printList();
+
+ list.insertAfter(10, 15);
+ std::cout << "After InsertAfter: ";
+ list.printList();
+
+ list.insertBefore(30, 25);
+ std::cout << "After InsertBefore: ";
+ list.printList();
+
+ list.clear();
+ std::cout << "After Clear: ";
+ list.printList();
+}
+
+int main() {
+ runTests();
+ return 0;
+}