aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor McDowell <[email protected]>2024-02-10 11:16:34 -0800
committerConnor McDowell <[email protected]>2024-02-10 11:16:34 -0800
commit8c40c473ab5698ad7e510fe742d46a0e641e6cd8 (patch)
treebf8023dd373c6f0ec4c5693d7a997e50ac0c4a55
parentohmygoditallworks (diff)
downloadin-class-exercise-10-connormcdowell275-8c40c473ab5698ad7e510fe742d46a0e641e6cd8.tar.xz
in-class-exercise-10-connormcdowell275-8c40c473ab5698ad7e510fe742d46a0e641e6cd8.zip
there was an incorrectness, newNode and nextNode's swap did not persist after the function ended
-rw-r--r--Inclass 10/PointerExamples.cpp5
-rw-r--r--Inclass 10/program.cpp2
2 files changed, 5 insertions, 2 deletions
diff --git a/Inclass 10/PointerExamples.cpp b/Inclass 10/PointerExamples.cpp
index 3a652e0..4a1bc7a 100644
--- a/Inclass 10/PointerExamples.cpp
+++ b/Inclass 10/PointerExamples.cpp
@@ -8,9 +8,10 @@ using std::endl;
void Swap(Node* first, Node* second)
{
- int test;
+ int test, test2;
test = first->data;
- first->data = second->data;
+ test2 = second->data;
+ first->data = test2;
second->data = test;
cout << test << endl;
diff --git a/Inclass 10/program.cpp b/Inclass 10/program.cpp
index fb9b9c6..e591996 100644
--- a/Inclass 10/program.cpp
+++ b/Inclass 10/program.cpp
@@ -25,6 +25,8 @@ int main()
newNode.next = &nextNode;
+ cout << nextNode.data << endl;
+
Swap(&newNode, &nextNode);
cout << "first node swapped is: " << newNode.data << " the second node swapped is : " << nextNode.data << endl;