From 21a0c870a29e15ddfcdd799824ead51a5e5132a5 Mon Sep 17 00:00:00 2001 From: Amrit Panesar Date: Tue, 8 Sep 2015 22:28:17 -0700 Subject: [PATCH] Linked List Node Manager/Lab3/Rolodex prep Signed-off-by: Amrit Panesar --- COM390/Lab3/Lab3.sln | 20 +++++++ COM390/Lab3/Lab3/Lab3.h | 9 +++ COM390/Lab3/Lab3/Lab3.vcxproj | 71 +++++++++++++++++++++++ COM390/Lab3/Lab3/Lab3.vcxproj.filters | 17 ++++++ COM390/Lab3/Lab3/Main.c | 5 ++ COM390/Lab3/Lab3/Node.c | 16 ++++++ COM390/Lab3/Lab3/Node.h | 20 +++++++ COM390/Lab3/Lab3/NodeManager.c | 81 +++++++++++++++++++++++++++ COM390/Lab3/Lab3/NodeManager.h | 29 ++++++++++ COM390/Lab3/Lab3/common.h | 13 +++++ 10 files changed, 281 insertions(+) create mode 100644 COM390/Lab3/Lab3.sln create mode 100644 COM390/Lab3/Lab3/Lab3.h create mode 100644 COM390/Lab3/Lab3/Lab3.vcxproj create mode 100644 COM390/Lab3/Lab3/Lab3.vcxproj.filters create mode 100644 COM390/Lab3/Lab3/Main.c create mode 100644 COM390/Lab3/Lab3/Node.c create mode 100644 COM390/Lab3/Lab3/Node.h create mode 100644 COM390/Lab3/Lab3/NodeManager.c create mode 100644 COM390/Lab3/Lab3/NodeManager.h create mode 100644 COM390/Lab3/Lab3/common.h diff --git a/COM390/Lab3/Lab3.sln b/COM390/Lab3/Lab3.sln new file mode 100644 index 0000000..453adc8 --- /dev/null +++ b/COM390/Lab3/Lab3.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab3", "Lab3\Lab3.vcxproj", "{6E969A73-34CC-4C13-973E-44245B3EF84B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6E969A73-34CC-4C13-973E-44245B3EF84B}.Debug|Win32.ActiveCfg = Debug|Win32 + {6E969A73-34CC-4C13-973E-44245B3EF84B}.Debug|Win32.Build.0 = Debug|Win32 + {6E969A73-34CC-4C13-973E-44245B3EF84B}.Release|Win32.ActiveCfg = Release|Win32 + {6E969A73-34CC-4C13-973E-44245B3EF84B}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/COM390/Lab3/Lab3/Lab3.h b/COM390/Lab3/Lab3/Lab3.h new file mode 100644 index 0000000..e49d405 --- /dev/null +++ b/COM390/Lab3/Lab3/Lab3.h @@ -0,0 +1,9 @@ + +//include node manager +#include "NodeManager.h" + +// standard libraries +#include +#include +#include +#include \ No newline at end of file diff --git a/COM390/Lab3/Lab3/Lab3.vcxproj b/COM390/Lab3/Lab3/Lab3.vcxproj new file mode 100644 index 0000000..348758e --- /dev/null +++ b/COM390/Lab3/Lab3/Lab3.vcxproj @@ -0,0 +1,71 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {6E969A73-34CC-4C13-973E-44245B3EF84B} + Lab3 + + + + Application + true + v110 + MultiByte + + + Application + false + v110 + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + true + + + true + + + + + Level3 + MaxSpeed + true + true + true + + + true + true + true + + + + + + + + \ No newline at end of file diff --git a/COM390/Lab3/Lab3/Lab3.vcxproj.filters b/COM390/Lab3/Lab3/Lab3.vcxproj.filters new file mode 100644 index 0000000..d7ef6a1 --- /dev/null +++ b/COM390/Lab3/Lab3/Lab3.vcxproj.filters @@ -0,0 +1,17 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;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 + + + \ No newline at end of file diff --git a/COM390/Lab3/Lab3/Main.c b/COM390/Lab3/Lab3/Main.c new file mode 100644 index 0000000..5eff625 --- /dev/null +++ b/COM390/Lab3/Lab3/Main.c @@ -0,0 +1,5 @@ +#include "Lab3.h" + +int main(int argc, char[]* argv) { + +} \ No newline at end of file diff --git a/COM390/Lab3/Lab3/Node.c b/COM390/Lab3/Lab3/Node.c new file mode 100644 index 0000000..455f5f4 --- /dev/null +++ b/COM390/Lab3/Lab3/Node.c @@ -0,0 +1,16 @@ +#include "Node.h" + +void Node::Init(int aIn, float bIn, char *nameIn) { + a = aIn; + b = bIn; + name = nameIn; +} + +NodeP NewNode(int aIn, float bIn, char *nameIn) { + NodeP out; + + out = (NodeP)malloc(sizeof(Node)); + out->Init(aIn, bIn, nameIn); + + return out; +} \ No newline at end of file diff --git a/COM390/Lab3/Lab3/Node.h b/COM390/Lab3/Lab3/Node.h new file mode 100644 index 0000000..27ac8a7 --- /dev/null +++ b/COM390/Lab3/Lab3/Node.h @@ -0,0 +1,20 @@ +#include "common.h" + +#ifndef H_NODE +#define H_NODE + + +typedef struct { + int a; + float b; + char *name; + + NodeP left; + NodeP right; + NodeP self; + + void Init(int aIn, float bIn, char *nameIn); + +}Node, *NodeP; + +#endif \ No newline at end of file diff --git a/COM390/Lab3/Lab3/NodeManager.c b/COM390/Lab3/Lab3/NodeManager.c new file mode 100644 index 0000000..a89d17a --- /dev/null +++ b/COM390/Lab3/Lab3/NodeManager.c @@ -0,0 +1,81 @@ +#include "NodeManager.h" + +void NodeManager::Init(int initialSize) { + Nodes = (NodeP*)malloc(sizeof(NodeP) * initialSize); +} + +int NodeManager::Add(NodeP nodeIn) { + NodeP arrnode; + + if (nodeCount + 1 > allocatedCount) { + Nodes = (NodeP*)realloc(Nodes, sizeof(Node) * nodeCount); + } + + // inserts at end + Nodes[nodeCount] = nodeIn; + Nodes[nodeCount]->self = nodeIn; + Nodes[nodeCount]->left = Nodes[nodeCount-1]; + + Nodes[nodeCount-1]->right = nodeIn; + + nodeCount++; + Sort(); +} + +void NodeManager::Sort() { + // A-Za-z0-9 sort + int i = 0; + + if (nodeCount < 2) { + return; + } + + for (i = 0; i < nodeCount-1; i++) { + if (strcmp(Nodes[i]->name, Nodes[i+1]->name) > 0) { + Swap(i, i+1); + } + } +} + +void NodeManager::Swap(int id1, int id2) { + NodeP one, two; + + //left node + one = Nodes[id1]->left; + two = Nodes[id2]->left; + Nodes[id1]->left = two; + Nodes[id2]->left = one; + + //right node + one = Nodes[id1]->right; + two = Nodes[id2]->right; + Nodes[id1]->right = two; + Nodes[id2]->right = one; + + //node entry + one = Nodes[id1]; + two = Nodes[id2]; + Nodes[id1] = two; + Nodes[id2] = one; +} + +NodeP NodeManager::GetAt(int index) { + +} + +boolean NodeManager::InsertAt(int index, NodeP nodeIn) { + +} + +boolean NodeManager::DeleteAt(int index) { + +} + +NodeManagerP NewNodeManager(int size) { + NodeManagerP nodem; + + nodem = (NodeManagerP)malloc(sizeof(NodeManager)); + nodem->Init(5); + + return nodem; +} \ No newline at end of file diff --git a/COM390/Lab3/Lab3/NodeManager.h b/COM390/Lab3/Lab3/NodeManager.h new file mode 100644 index 0000000..f501ced --- /dev/null +++ b/COM390/Lab3/Lab3/NodeManager.h @@ -0,0 +1,29 @@ +#include "Node.h" +#include "common.h" + +#ifndef H_NODEMANAGER +#define H_NODEMANAGER + +typedef struct { +private: + int allocatedCount; + int nodeCount; + +public: + NodeP *Nodes; + + void Init(int initialSize); + + int Add(NodeP nodeIn); + NodeP GetAt(int index); + boolean InsertAt(int index, NodeP nodeIn); + boolean DeleteAt(int index); + + void Sort(); + void Swap(int id1, int id2); + +} NodeManager, *NodeManagerP; + +NodeManagerP NewNodeManager(int size); + +#endif \ No newline at end of file diff --git a/COM390/Lab3/Lab3/common.h b/COM390/Lab3/Lab3/common.h new file mode 100644 index 0000000..7d1e3be --- /dev/null +++ b/COM390/Lab3/Lab3/common.h @@ -0,0 +1,13 @@ +#include +#include + +#ifndef boolean + +typedef int bool_t; + +#define boolean bool_t + +#define true 1 +#define false 0 + +#endif \ No newline at end of file