From 8dd91c25e4174dd771ea428b78925c52a4307445 Mon Sep 17 00:00:00 2001 From: Nataliia Brown Date: Mon, 12 Feb 2024 08:57:28 -0800 Subject: first function added --- In-Class Exercise 10/In-Class Exercise 10/Node.h | 7 ++++--- .../In-Class Exercise 10/PointerExamples.cpp | 10 ++++++---- In-Class Exercise 10/In-Class Exercise 10/PointerExamples.h | 3 +++ In-Class Exercise 10/In-Class Exercise 10/program.cpp | 12 ++++++------ 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); -- cgit v1.2.3