Linked List Node Manager/Lab3/Rolodex prep
Signed-off-by: Amrit Panesar <apanesar@4195tech.com>
This commit is contained in:
1 parent
70d7faed2c
commit
21a0c870a2
10 files changed
+281
No files matched your search
@@ -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
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
//include node manager
|
||||
#include "NodeManager.h"
|
||||
|
||||
// standard libraries
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#include <Windows.h>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{6E969A73-34CC-4C13-973E-44245B3EF84B}</ProjectGuid>
|
||||
<RootNamespace>Lab3</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v110</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</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>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "Lab3.h"
|
||||
|
||||
int main(int argc, char[]* argv) {
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef boolean
|
||||
|
||||
typedef int bool_t;
|
||||
|
||||
#define boolean bool_t
|
||||
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user