Skip to content

Commit

Permalink
Added DSA Trees and Traversals homework
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolavn committed Nov 4, 2015
1 parent fa155a2 commit 702dec7
Show file tree
Hide file tree
Showing 15 changed files with 460 additions and 6 deletions.
18 changes: 18 additions & 0 deletions DSA/02. Linear Data Structures/02.Linear Data Structures.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "09.First50OfSequence", "09.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "10.ShortestSequenceOfOperations", "10.ShortestSequenceOfOperations\10.ShortestSequenceOfOperations.csproj", "{06FBD1BC-D765-4411-941E-EC93B8BBF5DE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "11.LinkedListTask", "11.LinkedListTask\11.LinkedListTask.csproj", "{D4B272A1-A8DF-4309-A887-C5A5230E726F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "12.StackTask", "12.StackTask\12.StackTask.csproj", "{B40E700E-8445-45EA-A4F8-1D2532B8DE28}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "13.LinkedQueueTask", "13.LinkedQueueTask\13.LinkedQueueTask.csproj", "{7501FB1A-3C03-4620-947D-4A062FDE5FAC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -69,6 +75,18 @@ Global
{06FBD1BC-D765-4411-941E-EC93B8BBF5DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06FBD1BC-D765-4411-941E-EC93B8BBF5DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06FBD1BC-D765-4411-941E-EC93B8BBF5DE}.Release|Any CPU.Build.0 = Release|Any CPU
{D4B272A1-A8DF-4309-A887-C5A5230E726F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4B272A1-A8DF-4309-A887-C5A5230E726F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4B272A1-A8DF-4309-A887-C5A5230E726F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4B272A1-A8DF-4309-A887-C5A5230E726F}.Release|Any CPU.Build.0 = Release|Any CPU
{B40E700E-8445-45EA-A4F8-1D2532B8DE28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B40E700E-8445-45EA-A4F8-1D2532B8DE28}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B40E700E-8445-45EA-A4F8-1D2532B8DE28}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B40E700E-8445-45EA-A4F8-1D2532B8DE28}.Release|Any CPU.Build.0 = Release|Any CPU
{7501FB1A-3C03-4620-947D-4A062FDE5FAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7501FB1A-3C03-4620-947D-4A062FDE5FAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7501FB1A-3C03-4620-947D-4A062FDE5FAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7501FB1A-3C03-4620-947D-4A062FDE5FAC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_11.LinkedListTask</RootNamespace>
<AssemblyName>_11.LinkedListTask</AssemblyName>
<AssemblyName>11.LinkedListTask</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down Expand Up @@ -43,7 +43,9 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="LinkedListImplementation\LinkedList.cs" />
<Compile Include="LinkedListImplementation\ListItem.cs" />
<Compile Include="Startup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_12.StackTask</RootNamespace>
<AssemblyName>_12.StackTask</AssemblyName>
<AssemblyName>12.StackTask</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down Expand Up @@ -43,7 +43,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="StackImplementation\CustomStack.cs" />
<Compile Include="Startup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>_13.LinkedQueueTask</RootNamespace>
<AssemblyName>_13.LinkedQueueTask</AssemblyName>
<AssemblyName>13.LinkedQueueTask</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down Expand Up @@ -43,7 +43,8 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="LinkedQueueImplementation\CustomLinkedQueue.cs" />
<Compile Include="Startup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2E12EA55-C5D6-41B2-B0BE-1E1C63EF4C58}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FindExecutableFiles</RootNamespace>
<AssemblyName>FindExecutableFiles</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Startup.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("FindExecutableFiles")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FindExecutableFiles")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2e12ea55-c5d6-41b2-b0be-1e1c63ef4c58")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
namespace FindExecutableFiles
{
using System;
using System.Collections.Specialized;
using System.IO;

class Startup
{
static StringCollection log = new StringCollection();

static void Main()
{
DirectoryInfo root = new DirectoryInfo("C:\\Windows");

WalkDirectoryTree(root);
}

static void WalkDirectoryTree(DirectoryInfo root)
{
FileInfo[] files = null;
DirectoryInfo[] subDirs = null;

try
{
files = root.GetFiles("*.*");
}

catch (UnauthorizedAccessException e)
{
// This code just writes out the message and continues to recurse.
// You may decide to do something different here. For example, you
// can try to elevate your privileges and access the file again.
log.Add(e.Message);
}

catch (DirectoryNotFoundException e)
{
Console.WriteLine(e.Message);
}

if (files != null)
{
foreach (FileInfo fi in files)
{
// In this example, we only access the existing FileInfo object. If we
// want to open, delete or modify the file, then
// a try-catch block is required here to handle the case
// where the file has been deleted since the call to TraverseTree().
if (fi.Extension==".exe")
{
Console.WriteLine(fi.FullName);
}
}

// Now find all the subdirectories under this directory.
subDirs = root.GetDirectories();

foreach (DirectoryInfo dirInfo in subDirs)
{
// Resursive call for each subdirectory.
WalkDirectoryTree(dirInfo);
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TreeImplementation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TreeImplementation")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ac6bc774-208b-4254-a2ae-cc662c38e654")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TreeImplementation
{
class Startup
{
static void Main()
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace TreeImplementation
{
using System;

public class Tree<T>
{
private TreeNode<T> root;

public Tree(T value)
{
if (value == null)
{
throw new ArgumentNullException("Cannot insert null value!");
}

this.root = new TreeNode<T>(value);
}

public Tree(T value, params Tree<T>[] children)
: this(value)
{
foreach (Tree<T> child in children)
{
this.root.AddChild(child.root);
}
}

public TreeNode<T> Root
{
get
{
return this.root;
}
}

private void PrintDFS(TreeNode<T> root, string spaces)
{
if (this.root == null)
{
return;
}

Console.WriteLine(spaces + root.Value);

TreeNode<T> child = null;
for (int i = 0; i < root.ChildrenCount; i++)
{
child = root.GetChild(i);
PrintDFS(child, spaces + " ");
}
}

public void PrintDFS()
{
this.PrintDFS(this.root, string.Empty);
}
}
}
Loading

0 comments on commit 702dec7

Please sign in to comment.