projects 3, 4, and 5

This commit is contained in:
Fennel Kora 2023-06-23 19:29:02 -04:00
parent 036bfeeda7
commit f789abddb2
20 changed files with 1250 additions and 0 deletions

92
Project3/Project3.cpp Normal file
View file

@ -0,0 +1,92 @@
//Corey Williams
//COP3530 01Z
//Project 4
/*Write a C++ or Java application that creates a linked list of Circle objects/structures (i.e., class must be created).
The application can use the "IntSLLNode" and "IntSLList" classes (pp. 78 - 83) as a guide.
The application must provide the following features.
Allow insertion of multiple "Circle" objects/structures.
The Circle contains a "radius" data member.
The Circle also uses functions/methods "setRadius", "getRadius" and calculateArea (returns a double data type).
Invoke a method/function "DisplayAllElements" (i.e., must be written, traversal required; refer to "isInList" method, pg. 80) that receives
a "reference/pointer" formal parameter. This formal parameter specifies the "head" of the list.
The function/method must display all elements "position", "radius" , and "area"
*/
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
using namespace std;
class Circle {
private:
double radius;
public:
Circle(double r) {
radius = r;
}
double getRadius() {
return radius;
}
void setRadius(double r) {
radius = r;
}
double calculateArea() {
return M_PI * radius * radius;
}
};
class CirSLLNode {
public:
CirSLLNode() {
next = 0;
}
CirSLLNode(int el, CirSLLNode* ptr = 0) {
info = el; next = ptr;
}
int info;
CirSLLNode* next;
};
class CirSLList {
public:
CirSLList() {
head = tail = 0;
}
~CirSLList();
int isEmpty() {
return head == 0;
}
void addNode(Circle);
private:
CirSLLNode* head, * tail;
};
int main()
{
double r;
string userResp;
do {
cout << "Enter radius for first circle: ";
cin >> r;
Circle tmpCir(r);
//add tmpCir to linked list
cout << "Would you like to add another circle? Y/N: ";
cin >> userResp;
} while (userResp != "N" and userResp != "n");
}

31
Project3/Project3.sln Normal file
View file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33801.468
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project3", "Project3.vcxproj", "{8D2214F5-A52E-4E45-A765-0C785D99B33F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8D2214F5-A52E-4E45-A765-0C785D99B33F}.Debug|x64.ActiveCfg = Debug|x64
{8D2214F5-A52E-4E45-A765-0C785D99B33F}.Debug|x64.Build.0 = Debug|x64
{8D2214F5-A52E-4E45-A765-0C785D99B33F}.Debug|x86.ActiveCfg = Debug|Win32
{8D2214F5-A52E-4E45-A765-0C785D99B33F}.Debug|x86.Build.0 = Debug|Win32
{8D2214F5-A52E-4E45-A765-0C785D99B33F}.Release|x64.ActiveCfg = Release|x64
{8D2214F5-A52E-4E45-A765-0C785D99B33F}.Release|x64.Build.0 = Release|x64
{8D2214F5-A52E-4E45-A765-0C785D99B33F}.Release|x86.ActiveCfg = Release|Win32
{8D2214F5-A52E-4E45-A765-0C785D99B33F}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BAED36CB-181C-4D78-B2ED-CAE7DB7B6B89}
EndGlobalSection
EndGlobal

135
Project3/Project3.vcxproj Normal file
View file

@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{8d2214f5-a52e-4e45-a765-0c785d99b33f}</ProjectGuid>
<RootNamespace>Project3</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</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>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<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|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Project3.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,22 @@
<?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;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;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>
<ItemGroup>
<ClCompile Include="Project3.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

90
Project3/intSLList.cpp Normal file
View file

@ -0,0 +1,90 @@
//************************ intSLList.cpp **************************
#include <iostream.h>
#include "intSLList.h"
IntSLList::~IntSLList() {
for (IntSLLNode *p; !isEmpty(); ) {
p = head->next;
delete head;
head = p;
}
}
void IntSLList::addToHead(int el) {
head = new IntSLLNode(el,head);
if (tail == 0)
tail = head;
}
void IntSLList::addToTail(int el) {
if (tail != 0) { // if list not empty;
tail->next = new IntSLLNode(el);
tail = tail->next;
}
else head = tail = new IntSLLNode(el);
}
int IntSLList::deleteFromHead() {
int el = head->info;
IntSLLNode *tmp = head;
if (head == tail) // if only one node on the list;
head = tail = 0;
else head = head->next;
delete tmp;
return el;
}
int IntSLList::deleteFromTail() {
int el = tail->info;
if (head == tail) { // if only one node on the list;
delete head;
head = tail = 0;
}
else { // if more than one node in the list,
IntSLLNode *tmp; // find the predecessor of tail;
for (tmp = head; tmp->next != tail; tmp = tmp->next);
delete tail;
tail = tmp; // the predecessor of tail becomes tail;
tail->next = 0;
}
return el;
}
void IntSLList::deleteNode(int el) {
if (head != 0) // if non-empty list;
if (head == tail && el == head->info) { // if only one
delete head; // node on the list;
head = tail = 0;
}
else if (el == head->info) { // if more than one node on the list
IntSLLNode *tmp = head;
head = head->next;
delete tmp; // and old head is deleted;
}
else { // if more than one node in the list
IntSLLNode *pred, *tmp;
for (pred = head, tmp = head->next; // and a non-head node
tmp != 0 && !(tmp->info == el);// is deleted;
pred = pred->next, tmp = tmp->next);
if (tmp != 0) {
pred->next = tmp->next;
if (tmp == tail)
tail = pred;
delete tmp;
}
}
}
bool IntSLList::isInList(int el) const {
IntSLLNode *tmp;
for (tmp = head; tmp != 0 && !(tmp->info == el); tmp = tmp->next);
return tmp != 0;
}
void IntSLList::printAll() const {
for (IntSLLNode *tmp = head; tmp != 0; tmp = tmp->next)
cout << tmp->info << " ";
cout << endl;
}

39
Project3/intSLList.h Normal file
View file

@ -0,0 +1,39 @@
//************************ intSLList.h **************************
// singly-linked list class to store integers
#ifndef INT_LINKED_LIST
#define INT_LINKED_LIST
class IntSLLNode {
public:
IntSLLNode() {
next = 0;
}
IntSLLNode(int el, IntSLLNode *ptr = 0) {
info = el; next = ptr;
}
int info;
IntSLLNode *next;
};
class IntSLList {
public:
IntSLList() {
head = tail = 0;
}
~IntSLList();
int isEmpty() {
return head == 0;
}
void addToHead(int);
void addToTail(int);
int deleteFromHead(); // delete the head and return its info;
int deleteFromTail(); // delete the tail and return its info;
void deleteNode(int);
bool isInList(int) const;
void printAll() const;
private:
IntSLLNode *head, *tail;
};
#endif

41
Project4/Project4.cpp Normal file
View file

@ -0,0 +1,41 @@
//Corey Williams
//COP3530 01Z
//Project 4
/*Write a C++ or Java application that creates a linked list of Circle objects/structures (i.e., class must be created).
The application can use the "IntSLLNode" and "IntSLList" classes (pp. 78 - 83) as a guide.
The application must provide the following features.
Allow insertion of multiple "Circle" objects/structures.
The Circle contains a "radius" data member.
The Circle also uses functions/methods "setRadius", "getRadius" and calculateArea (returns a double data type).
Invoke a method/function "DisplayAllElements" (i.e., must be written, traversal required; refer to "isInList" method, pg. 80) that receives
a "reference/pointer" formal parameter. This formal parameter specifies the "head" of the list.
The function/method must display all elements "position", "radius" , and "area"
*/
#include <iostream>
#include "cirSLList.h"
#include "circle.h"
using namespace std;
int main()
{
double r;
string userResp;
cirSLList CircleList;
do {
cout << "Enter radius for circle: ";
cin >> r;
CircleList.addToTail(r);
cout << "Would you like to add another circle? Y/N: ";
cin >> userResp;
} while (userResp != "N" and userResp != "n");
CircleList.displayAllElements();
}

31
Project4/Project4.sln Normal file
View file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33801.468
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project4", "Project4.vcxproj", "{1567CA04-7F5A-485C-BF7A-7A499ECD2102}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Debug|x64.ActiveCfg = Debug|x64
{1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Debug|x64.Build.0 = Debug|x64
{1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Debug|x86.ActiveCfg = Debug|Win32
{1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Debug|x86.Build.0 = Debug|Win32
{1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Release|x64.ActiveCfg = Release|x64
{1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Release|x64.Build.0 = Release|x64
{1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Release|x86.ActiveCfg = Release|Win32
{1567CA04-7F5A-485C-BF7A-7A499ECD2102}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {01E804E5-D748-4033-8FDF-639ED6D999A9}
EndGlobalSection
EndGlobal

139
Project4/Project4.vcxproj Normal file
View file

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{1567ca04-7f5a-485c-bf7a-7a499ecd2102}</ProjectGuid>
<RootNamespace>Project4</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</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>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<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|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="cirSLList.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="cirSLList.cpp" />
<ClCompile Include="Project4.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,30 @@
<?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;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;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>
<ItemGroup>
<ClCompile Include="cirSLList.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Project4.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="cirSLList.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

35
Project4/cirSLList.cpp Normal file
View file

@ -0,0 +1,35 @@
//************************ cirSLList.cpp **************************
#include <iostream>
#include "cirSLList.h"
#include "circle.h"
using namespace std;
cirSLList::~cirSLList() {
for (cirSLLNode *p; !isEmpty(); ) {
p = head->next;
delete head;
head = p;
}
}
void cirSLList::addToTail(double el) {
if (tail != 0) { // if list not empty;
tail->next = new cirSLLNode(el);
tail = tail->next;
}
else head = tail = new cirSLLNode(el);
}
void cirSLList::displayAllElements() {
int i = 1;
for (cirSLLNode* tmp = head; tmp != 0; tmp = tmp->next) {
cout << i << ". ";
cout << "Radius: " << tmp->info.getRadius() << " - ";
cout << "Area: " << tmp->info.calculateArea() << endl;
i++;
}
cout << endl;
}

34
Project4/cirSLList.h Normal file
View file

@ -0,0 +1,34 @@
//************************ cirSLList.h **************************
// singly-linked list class to store integers
#ifndef INT_LINKED_LIST
#define INT_LINKED_LIST
#include "circle.h"
class cirSLLNode {
public:
Circle info;
cirSLLNode(double el, cirSLLNode *ptr = 0) {
info.setRadius(el); next = ptr;
}
cirSLLNode *next;
};
class cirSLList {
public:
cirSLList() {
head = tail = NULL;
}
~cirSLList();
int isEmpty() {
return head == 0;
}
void addToTail(double);
bool isInList(Circle) const;
void displayAllElements();
private:
cirSLLNode *head, *tail;
};
#endif

29
Project4/circle.cpp Normal file
View file

@ -0,0 +1,29 @@
#define _USE_MATH_DEFINES
#include <math.h>
class Circle {
private:
double radius;
public:
Circle() {
radius = 0;
}
Circle(double r) {
radius = r;
}
double getRadius() {
return radius;
}
void setRadius(double r) {
radius = r;
}
double calculateArea() {
return M_PI * radius * radius;
}
};

34
Project4/circle.h Normal file
View file

@ -0,0 +1,34 @@
#ifndef CIRCLE_HEADER
#define CIRCLE_HEADER
#define _USE_MATH_DEFINES
#include <math.h>
class Circle {
private:
double radius;
public:
Circle() {
radius = 0;
}
Circle(double r) {
radius = r;
}
double getRadius() {
return radius;
}
void setRadius(double r) {
radius = r;
}
double calculateArea() {
return M_PI * radius * radius;
}
};
#endif

108
Project5/Project5.cpp Normal file
View file

@ -0,0 +1,108 @@
// Corey Williams
// COP3530 01Z
//Project 5
//10. Write a member function to check whether two singly linked lists have the same contents
#include <iostream>
#include "intSLList.h"
using namespace std;
void testOutput(bool result, bool expResult) {
if (result == expResult) { cout << "TEST PASS"; }
else { cout << "TEST FAIL"; }
cout << " Expected: " << expResult << " | Actual : " << result << endl;
}
int main()
{
IntSLList listA;
IntSLList listB;
int arrA[5] = { 2, 24, -1, 88, 3 };
//Test 1: Test two linked lists that are equivalent elements and same length - Expected result is TRUE (1)
//Loads arrA into both linked lists
for (int i = 0; i < 5; i++) {
listA.addToTail(arrA[i]);
listB.addToTail(arrA[i]);
}
testOutput(listA.isEqual(listB.getHeadElement()), true);
listA.printAll();
listB.printAll();
//Clear listB for new test
while (!listB.isEmpty()) { listB.deleteFromTail(); }
//Test 2: Test two linked lists that are unequal but the same length - Expected result is FALSE (0)
int arrB[5] = { 2, 24, -1, 88, 5 };
for (int i = 0; i < 5; i++) {
listB.addToTail(arrB[i]);
}
testOutput(listA.isEqual(listB.getHeadElement()), false);
listA.printAll();
listB.printAll();
//Clear listB for new test
while (!listB.isEmpty()) { listB.deleteFromTail(); }
//Test 3: Test two linked lists that are unequal and the second list is longer - Expected result is FALSE (0)
int arrC[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
for (int i = 0; i < sizeof(arrC)/sizeof(arrC[0]); i++) {
listB.addToTail(arrC[i]);
}
testOutput(listA.isEqual(listB.getHeadElement()), false);
listA.printAll();
listB.printAll();
//Clear listB for new test
while (!listB.isEmpty()) { listB.deleteFromTail(); }
//Test 4: Test two linked lists that are unequal and the second list is shorter - Expected result is FALSE (0)
int arrD[3] = { 1, 2, 3 };
for (int i = 0; i < sizeof(arrD) / sizeof(arrD[0]); i++) {
listB.addToTail(arrD[i]);
}
testOutput(listA.isEqual(listB.getHeadElement()), false);
listA.printAll();
listB.printAll();
//Clear listB for new test
while (!listB.isEmpty()) { listB.deleteFromTail(); }
//Test 5: Test two linked lists where the first list is a subset of the second - Expected result is FALSE (0)
int arrE[8] = { 2, 24, -1, 88, 3, 6, 7, 8 };
for (int i = 0; i < sizeof(arrE) / sizeof(arrE[0]); i++) {
listB.addToTail(arrE[i]);
}
testOutput(listA.isEqual(listB.getHeadElement()), false);
listA.printAll();
listB.printAll();
//Clear listB for new test
while (!listB.isEmpty()) { listB.deleteFromTail(); }
//Test 6: Test two linked lists where the second list is a subset of the first - Expected result is FALSE (0)
int arrF[4] = { 2, 24, -1, 88 };
for (int i = 0; i < sizeof(arrF) / sizeof(arrF[0]); i++) {
listB.addToTail(arrF[i]);
}
testOutput(listA.isEqual(listB.getHeadElement()), false);
listA.printAll();
listB.printAll();
//Clear listB for new test
while (!listB.isEmpty()) { listB.deleteFromTail(); }
}

31
Project5/Project5.sln Normal file
View file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33801.468
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project5", "Project5.vcxproj", "{55494E87-AC76-4675-B4B1-E3752AEE567E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{55494E87-AC76-4675-B4B1-E3752AEE567E}.Debug|x64.ActiveCfg = Debug|x64
{55494E87-AC76-4675-B4B1-E3752AEE567E}.Debug|x64.Build.0 = Debug|x64
{55494E87-AC76-4675-B4B1-E3752AEE567E}.Debug|x86.ActiveCfg = Debug|Win32
{55494E87-AC76-4675-B4B1-E3752AEE567E}.Debug|x86.Build.0 = Debug|Win32
{55494E87-AC76-4675-B4B1-E3752AEE567E}.Release|x64.ActiveCfg = Release|x64
{55494E87-AC76-4675-B4B1-E3752AEE567E}.Release|x64.Build.0 = Release|x64
{55494E87-AC76-4675-B4B1-E3752AEE567E}.Release|x86.ActiveCfg = Release|Win32
{55494E87-AC76-4675-B4B1-E3752AEE567E}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7BA3C2DE-C47D-4833-8BE7-E256AF5B6D42}
EndGlobalSection
EndGlobal

139
Project5/Project5.vcxproj Normal file
View file

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" 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>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{55494e87-ac76-4675-b4b1-e3752aee567e}</ProjectGuid>
<RootNamespace>Project5</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</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>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<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|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="intSLList.cpp" />
<ClCompile Include="Project5.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="intSLList.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,30 @@
<?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;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;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>
<ItemGroup>
<ClCompile Include="Project5.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="intSLList.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="intSLList.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

119
Project5/intSLList.cpp Normal file
View file

@ -0,0 +1,119 @@
//************************ intSLList.cpp **************************
#include <iostream>
#include "intSLList.h"
using namespace std;
IntSLList::~IntSLList() {
for (IntSLLNode *p; !isEmpty(); ) {
p = head->next;
delete head;
head = p;
}
}
void IntSLList::addToHead(int el) {
head = new IntSLLNode(el,head);
if (tail == 0)
tail = head;
}
void IntSLList::addToTail(int el) {
if (tail != 0) { // if list not empty;
tail->next = new IntSLLNode(el);
tail = tail->next;
}
else head = tail = new IntSLLNode(el);
}
int IntSLList::deleteFromHead() {
int el = head->info;
IntSLLNode *tmp = head;
if (head == tail) // if only one node on the list;
head = tail = 0;
else head = head->next;
delete tmp;
return el;
}
int IntSLList::deleteFromTail() {
int el = tail->info;
if (head == tail) { // if only one node on the list;
delete head;
head = tail = 0;
}
else { // if more than one node in the list,
IntSLLNode *tmp; // find the predecessor of tail;
for (tmp = head; tmp->next != tail; tmp = tmp->next);
delete tail;
tail = tmp; // the predecessor of tail becomes tail;
tail->next = 0;
}
return el;
}
void IntSLList::deleteNode(int el) {
if (head != 0) // if non-empty list;
if (head == tail && el == head->info) { // if only one
delete head; // node on the list;
head = tail = 0;
}
else if (el == head->info) { // if more than one node on the list
IntSLLNode *tmp = head;
head = head->next;
delete tmp; // and old head is deleted;
}
else { // if more than one node in the list
IntSLLNode *pred, *tmp;
for (pred = head, tmp = head->next; // and a non-head node
tmp != 0 && !(tmp->info == el);// is deleted;
pred = pred->next, tmp = tmp->next);
if (tmp != 0) {
pred->next = tmp->next;
if (tmp == tail)
tail = pred;
delete tmp;
}
}
}
bool IntSLList::isInList(int el) const {
IntSLLNode *tmp;
for (tmp = head; tmp != 0 && !(tmp->info == el); tmp = tmp->next);
return tmp != 0;
}
void IntSLList::printAll() const {
for (IntSLLNode *tmp = head; tmp != 0; tmp = tmp->next)
cout << tmp->info << " ";
cout << endl;
}
IntSLLNode* IntSLList::getHeadElement() {
return head;
}
//compares existing LL instance to a second LL instance passed in by its head node.
bool IntSLList::isEqual(IntSLLNode *comp) {
int i = 0, j = 0;
//Test that both lists are of the same length
for (IntSLLNode* countA = head; countA != 0; countA = countA->next) { i++; }
for (IntSLLNode* countComp = comp; countComp != 0; countComp = countComp->next) { j++; }
if (i != j) { return false; }
//Tests that both lists have the same elements
for (IntSLLNode *listA = head; listA != 0 && comp != 0; listA = listA->next) {
if (listA->info == comp->info && comp != 0 && listA != 0) {
comp = comp->next;
continue;
}
return false;
}
return true;
}

41
Project5/intSLList.h Normal file
View file

@ -0,0 +1,41 @@
//************************ intSLList.h **************************
// singly-linked list class to store integers
#ifndef INT_LINKED_LIST
#define INT_LINKED_LIST
class IntSLLNode {
public:
IntSLLNode() {
next = 0;
}
IntSLLNode(int el, IntSLLNode *ptr = 0) {
info = el; next = ptr;
}
int info;
IntSLLNode *next;
};
class IntSLList {
public:
IntSLList() {
head = tail = 0;
}
~IntSLList();
int isEmpty() {
return head == 0;
}
void addToHead(int);
void addToTail(int);
int deleteFromHead(); // delete the head and return its info;
int deleteFromTail(); // delete the tail and return its info;
void deleteNode(int);
bool isInList(int) const;
void printAll() const;
bool isEqual(IntSLLNode* comp);
IntSLLNode* getHeadElement();
private:
IntSLLNode *head, *tail;
};
#endif