aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--In-Class Exercise 10/In-Class Exercise 10/Node.h7
-rw-r--r--In-Class Exercise 10/In-Class Exercise 10/PointerExamples.cpp10
-rw-r--r--In-Class Exercise 10/In-Class Exercise 10/PointerExamples.h3
-rw-r--r--In-Class Exercise 10/In-Class Exercise 10/program.cpp12
4 files changed, 19 insertions, 13 deletions
diff --git a/In-Class Exercise 10/In-Class Exercise 10/Node.h b/In-Class Exercise 10/In-Class Exercise 10/Node.h
index a2a3fbd..8cd0803 100644
--- a/In-Class Exercise 10/In-Class Exercise 10/Node.h
+++ b/In-Class Exercise 10/In-Class Exercise 10/Node.h
@@ -1,10 +1,11 @@
#ifndef NODE_H
#define NODE_H
+#include "PointerExamples.h"
+
+
struct Node {
- int data;
- Node* _next;
- Node* _num;
+ int _num;
};
#endif \ No newline at end of file
diff --git a/In-Class Exercise 10/In-Class Exercise 10/PointerExamples.cpp b/In-Class Exercise 10/In-Class Exercise 10/PointerExamples.cpp
index ddd1096..493504c 100644
--- a/In-Class Exercise 10/In-Class Exercise 10/PointerExamples.cpp
+++ b/In-Class Exercise 10/In-Class Exercise 10/PointerExamples.cpp
@@ -10,10 +10,12 @@
void Swap(Node* first, Node* second)
{
- Node Node3{};
- Node3._num = first._num;
- first._num = second._num;
- second._num = Node3._num;
+ int temp = 0;
+
+ temp = first->_num;
+
+ first->_num=second->_num;
+ second->_num = temp;
}
void Standardize_101(Node* node) {
diff --git a/In-Class Exercise 10/In-Class Exercise 10/PointerExamples.h b/In-Class Exercise 10/In-Class Exercise 10/PointerExamples.h
index ebba5c4..5c532c4 100644
--- a/In-Class Exercise 10/In-Class Exercise 10/PointerExamples.h
+++ b/In-Class Exercise 10/In-Class Exercise 10/PointerExamples.h
@@ -1,6 +1,9 @@
#ifndef POINTER_EXAMPLES_H
#define POINTER_EXAMPLES_H
+#include "Node.h"
+
+
void Swap(Node *first, Node *second);
void Standardize_101(Node* node);
diff --git a/In-Class Exercise 10/In-Class Exercise 10/program.cpp b/In-Class Exercise 10/In-Class Exercise 10/program.cpp
index fb00933..fcbf6a0 100644
--- a/In-Class Exercise 10/In-Class Exercise 10/program.cpp
+++ b/In-Class Exercise 10/In-Class Exercise 10/program.cpp
@@ -15,17 +15,17 @@ using std::endl;
int main() {
Node firstNode{};
- firstNode.data = 438;
-
Node secondNode{};
- secondNode.data = 549;
- Node thirdNode{};
- thirdNode.data = 1452;
+ firstNode._num = 15;
+ secondNode._num = 20;
+
+
Swap(&firstNode, &secondNode);
- cout << "Firts Node is " << firstNode << endl;
+ cout << "Firts Node is " << firstNode._num << endl;
+ cout << "Second Node is " << secondNode._num << endl;
/*Standardize_101(&thirdNode);