lol
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.31808.319
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Linear Data Structures and Linked Lists", "Linear Data Structures and Linked Lists.vcxproj", "{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}"
|
||||
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
|
||||
{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}.Debug|x64.Build.0 = Debug|x64
|
||||
{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}.Debug|x86.Build.0 = Debug|Win32
|
||||
{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}.Release|x64.ActiveCfg = Release|x64
|
||||
{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}.Release|x64.Build.0 = Release|x64
|
||||
{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}.Release|x86.ActiveCfg = Release|Win32
|
||||
{667CD8AC-8201-452C-8FE7-EC68B2AFCD47}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {70604C3D-8764-4A7B-B2F1-E67DFBD75067}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,147 @@
|
||||
<?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>{667cd8ac-8201-452c-8fe7-ec68b2afcd47}</ProjectGuid>
|
||||
<RootNamespace>LinearDataStructuresandLinkedLists</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" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<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="main.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
6
Linear Data Structures and Linked Lists/main.cpp
Normal file
6
Linear Data Structures and Linked Lists/main.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello, world!" << std::endl;
|
||||
}
|
||||
@@ -1,84 +1,87 @@
|
||||
#include <iostream>
|
||||
|
||||
void PrintArr(int* arr, int size)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
std::cout << arr[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void ShuffleArr(int* arr, int size)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < size - 1; i++)
|
||||
{
|
||||
size_t j = i + rand() / (RAND_MAX / (size - i) + 1);
|
||||
int t = arr[j];
|
||||
arr[j] = arr[i];
|
||||
arr[i] = t;
|
||||
}
|
||||
}
|
||||
|
||||
void Swap(int* a, int* b)
|
||||
{
|
||||
int t = *a;
|
||||
*a = *b;
|
||||
*b = t;
|
||||
}
|
||||
|
||||
void CopyArr(int* source, int* target, int start, int end)
|
||||
{
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
target[i] = source[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Merge(int* arr, int start, int mid, int end)
|
||||
{
|
||||
std::cout << start << " " << mid << " " << end << std::endl;
|
||||
int* leftHalf = new int[mid - start + 1];
|
||||
int* rightHalf = new int[end - mid];
|
||||
|
||||
CopyArr(arr, leftHalf, 0, mid);
|
||||
CopyArr(arr, rightHalf, mid + 1, end);
|
||||
|
||||
// merge together
|
||||
int leftIndex = 0;
|
||||
int rightIndex = 0;
|
||||
for (int i = 0; i < end - start; i++)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MergeSort(int* arr, int start, int end)
|
||||
{
|
||||
int mid = start + (start + end) / 2;
|
||||
if (start >= end)
|
||||
MergeSort(arr, start, mid);
|
||||
MergeSort(arr, mid + 1, end);
|
||||
Merge(arr, start, mid, end);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int* arr = new int[100];
|
||||
for (int i = 0; i < 100; i++)
|
||||
arr[i] = i;
|
||||
|
||||
// MergeSort
|
||||
std::cout << "Merge Sort" << std::endl;
|
||||
ShuffleArr(arr, 100);
|
||||
MergeSort(arr, 0, 100);
|
||||
PrintArr(arr, 100);
|
||||
|
||||
// QuickSort
|
||||
ShuffleArr(arr, 100);
|
||||
|
||||
}
|
||||
#include <iostream>
|
||||
|
||||
void PrintArr(int* arr, int size)
|
||||
{
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
std::cout << arr[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void ShuffleArr(int* arr, int size)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < size - 1; i++)
|
||||
{
|
||||
size_t j = i + rand() / (RAND_MAX / (size - i) + 1);
|
||||
int t = arr[j];
|
||||
arr[j] = arr[i];
|
||||
arr[i] = t;
|
||||
}
|
||||
}
|
||||
|
||||
void Swap(int* a, int* b)
|
||||
{
|
||||
int t = *a;
|
||||
*a = *b;
|
||||
*b = t;
|
||||
}
|
||||
|
||||
void CopyArr(int* source, int* target, int start, int end)
|
||||
{
|
||||
for (int i = start; i < end; i++)
|
||||
{
|
||||
target[i] = source[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Merge(int* arr, int start, int mid, int end)
|
||||
{
|
||||
std::cout << start << " " << mid << " " << end << std::endl;
|
||||
int* leftHalf = new int[mid - start + 1];
|
||||
int* rightHalf = new int[end - mid];
|
||||
|
||||
CopyArr(arr, leftHalf, 0, mid);
|
||||
CopyArr(arr, rightHalf, mid + 1, end);
|
||||
|
||||
// merge together
|
||||
int leftIndex = 0;
|
||||
int rightIndex = 0;
|
||||
for (int i = 0; i < end - start; i++)
|
||||
{
|
||||
|
||||
}
|
||||
delete[] leftHalf;
|
||||
delete[] rightHalf;
|
||||
}
|
||||
|
||||
void MergeSort(int* arr, int start, int end)
|
||||
{
|
||||
int mid = (end - start) + (end / 2);
|
||||
if (start < end)
|
||||
{
|
||||
MergeSort(arr, start, mid);
|
||||
MergeSort(arr, mid + 1, end);
|
||||
}
|
||||
Merge(arr, start, mid, end);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int* arr = new int[100];
|
||||
for (int i = 0; i < 100; i++)
|
||||
arr[i] = i;
|
||||
|
||||
// MergeSort
|
||||
std::cout << "Merge Sort" << std::endl;
|
||||
ShuffleArr(arr, 100);
|
||||
MergeSort(arr, 0, 100);
|
||||
PrintArr(arr, 100);
|
||||
|
||||
// QuickSort
|
||||
ShuffleArr(arr, 100);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user