-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DSA Trees and Traversals homework
- Loading branch information
Showing
15 changed files
with
460 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/App.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
60 changes: 60 additions & 0 deletions
60
...03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/FindExecutableFiles.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
36 changes: 36 additions & 0 deletions
36
...03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")] |
66 changes: 66 additions & 0 deletions
66
DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/App.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
36 changes: 36 additions & 0 deletions
36
DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")] |
9 changes: 9 additions & 0 deletions
9
DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace TreeImplementation | ||
{ | ||
class Startup | ||
{ | ||
static void Main() | ||
{ | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Tree.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.