From 702dec7a25f3f2c7da6183630340cc2542d7a600 Mon Sep 17 00:00:00 2001 From: nikolavn Date: Wed, 4 Nov 2015 22:23:05 +0200 Subject: [PATCH] Added DSA Trees and Traversals homework --- .../02.Linear Data Structures.sln | 18 +++++ .../11.LinkedListTask.csproj | 6 +- .../12.StackTask/12.StackTask.csproj | 5 +- .../13.LinkedQueueTask.csproj | 5 +- .../FindExecutableFiles/App.config | 6 ++ .../FindExecutableFiles.csproj | 60 +++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ .../FindExecutableFiles/Startup.cs | 66 +++++++++++++++++++ .../TreeImplementation/App.config | 6 ++ .../Properties/AssemblyInfo.cs | 36 ++++++++++ .../TreeImplementation/Startup.cs | 9 +++ .../TreeImplementation/Tree.cs | 58 ++++++++++++++++ .../TreeImplementation.csproj | 62 +++++++++++++++++ .../TreeImplementation/TreeNode.cs | 65 ++++++++++++++++++ .../TreesAndTraversals/TreesAndTraversals.sln | 28 ++++++++ 15 files changed, 460 insertions(+), 6 deletions(-) create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/App.config create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/FindExecutableFiles.csproj create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Properties/AssemblyInfo.cs create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Startup.cs create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/App.config create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Properties/AssemblyInfo.cs create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Startup.cs create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Tree.cs create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/TreeImplementation.csproj create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/TreeNode.cs create mode 100644 DSA/03.Trees And Traversals/TreesAndTraversals/TreesAndTraversals.sln diff --git a/DSA/02. Linear Data Structures/02.Linear Data Structures.sln b/DSA/02. Linear Data Structures/02.Linear Data Structures.sln index da66083..21338ba 100644 --- a/DSA/02. Linear Data Structures/02.Linear Data Structures.sln +++ b/DSA/02. Linear Data Structures/02.Linear Data Structures.sln @@ -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 @@ -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 diff --git a/DSA/02. Linear Data Structures/11.LinkedListTask/11.LinkedListTask.csproj b/DSA/02. Linear Data Structures/11.LinkedListTask/11.LinkedListTask.csproj index eaf0ef2..1aa2bd3 100644 --- a/DSA/02. Linear Data Structures/11.LinkedListTask/11.LinkedListTask.csproj +++ b/DSA/02. Linear Data Structures/11.LinkedListTask/11.LinkedListTask.csproj @@ -8,7 +8,7 @@ Exe Properties _11.LinkedListTask - _11.LinkedListTask + 11.LinkedListTask v4.5.1 512 true @@ -43,7 +43,9 @@ - + + + diff --git a/DSA/02. Linear Data Structures/12.StackTask/12.StackTask.csproj b/DSA/02. Linear Data Structures/12.StackTask/12.StackTask.csproj index 57a3686..bb2c18f 100644 --- a/DSA/02. Linear Data Structures/12.StackTask/12.StackTask.csproj +++ b/DSA/02. Linear Data Structures/12.StackTask/12.StackTask.csproj @@ -8,7 +8,7 @@ Exe Properties _12.StackTask - _12.StackTask + 12.StackTask v4.5.1 512 true @@ -43,7 +43,8 @@ - + + diff --git a/DSA/02. Linear Data Structures/13.LinkedQueueTask/13.LinkedQueueTask.csproj b/DSA/02. Linear Data Structures/13.LinkedQueueTask/13.LinkedQueueTask.csproj index 2b49e2e..546e1e9 100644 --- a/DSA/02. Linear Data Structures/13.LinkedQueueTask/13.LinkedQueueTask.csproj +++ b/DSA/02. Linear Data Structures/13.LinkedQueueTask/13.LinkedQueueTask.csproj @@ -8,7 +8,7 @@ Exe Properties _13.LinkedQueueTask - _13.LinkedQueueTask + 13.LinkedQueueTask v4.5.1 512 true @@ -43,7 +43,8 @@ - + + diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/App.config b/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/App.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/FindExecutableFiles.csproj b/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/FindExecutableFiles.csproj new file mode 100644 index 0000000..4e86f5b --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/FindExecutableFiles.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {2E12EA55-C5D6-41B2-B0BE-1E1C63EF4C58} + Exe + Properties + FindExecutableFiles + FindExecutableFiles + v4.5.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Properties/AssemblyInfo.cs b/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fd0e221 --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Properties/AssemblyInfo.cs @@ -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")] diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Startup.cs b/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Startup.cs new file mode 100644 index 0000000..ce84241 --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/FindExecutableFiles/Startup.cs @@ -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); + } + } + } + } +} diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/App.config b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/App.config new file mode 100644 index 0000000..9c05822 --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Properties/AssemblyInfo.cs b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7dbe4a9 --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Properties/AssemblyInfo.cs @@ -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")] diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Startup.cs b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Startup.cs new file mode 100644 index 0000000..9f4f744 --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Startup.cs @@ -0,0 +1,9 @@ +namespace TreeImplementation +{ + class Startup + { + static void Main() + { + } + } +} diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Tree.cs b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Tree.cs new file mode 100644 index 0000000..c5b614f --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/Tree.cs @@ -0,0 +1,58 @@ +namespace TreeImplementation +{ + using System; + + public class Tree + { + private TreeNode root; + + public Tree(T value) + { + if (value == null) + { + throw new ArgumentNullException("Cannot insert null value!"); + } + + this.root = new TreeNode(value); + } + + public Tree(T value, params Tree[] children) + : this(value) + { + foreach (Tree child in children) + { + this.root.AddChild(child.root); + } + } + + public TreeNode Root + { + get + { + return this.root; + } + } + + private void PrintDFS(TreeNode root, string spaces) + { + if (this.root == null) + { + return; + } + + Console.WriteLine(spaces + root.Value); + + TreeNode 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); + } + } +} diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/TreeImplementation.csproj b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/TreeImplementation.csproj new file mode 100644 index 0000000..307717c --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/TreeImplementation.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {AC6BC774-208B-4254-A2AE-CC662C38E654} + Exe + Properties + TreeImplementation + TreeImplementation + v4.5.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/TreeNode.cs b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/TreeNode.cs new file mode 100644 index 0000000..cd36024 --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/TreeImplementation/TreeNode.cs @@ -0,0 +1,65 @@ +namespace TreeImplementation +{ + using System; + using System.Collections.Generic; + + public class TreeNode + { + private T value; + + private bool hasParent; + + private List> children; + + public TreeNode(T value) + { + if (value == null) + { + throw new ArgumentNullException("Cannot insert null value!"); + } + this.value = value; + this.children = new List>(); + } + + public T Value + { + get + { + return this.value; + } + set + { + this.value = value; + } + } + + public int ChildrenCount + { + get + { + return this.children.Count; + } + } + + public void AddChild(TreeNode child) + { + if (child == null) + { + throw new ArgumentNullException("Cannot insert null value!"); + } + + if (child.hasParent) + { + throw new ArgumentException("The node already has a parent!"); + } + + child.hasParent = true; + this.children.Add(child); + } + + public TreeNode GetChild(int index) + { + return this.children[index]; + } + } +} diff --git a/DSA/03.Trees And Traversals/TreesAndTraversals/TreesAndTraversals.sln b/DSA/03.Trees And Traversals/TreesAndTraversals/TreesAndTraversals.sln new file mode 100644 index 0000000..e3de331 --- /dev/null +++ b/DSA/03.Trees And Traversals/TreesAndTraversals/TreesAndTraversals.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TreeImplementation", "TreeImplementation\TreeImplementation.csproj", "{AC6BC774-208B-4254-A2AE-CC662C38E654}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FindExecutableFiles", "FindExecutableFiles\FindExecutableFiles.csproj", "{2E12EA55-C5D6-41B2-B0BE-1E1C63EF4C58}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {AC6BC774-208B-4254-A2AE-CC662C38E654}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AC6BC774-208B-4254-A2AE-CC662C38E654}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AC6BC774-208B-4254-A2AE-CC662C38E654}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AC6BC774-208B-4254-A2AE-CC662C38E654}.Release|Any CPU.Build.0 = Release|Any CPU + {2E12EA55-C5D6-41B2-B0BE-1E1C63EF4C58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E12EA55-C5D6-41B2-B0BE-1E1C63EF4C58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E12EA55-C5D6-41B2-B0BE-1E1C63EF4C58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E12EA55-C5D6-41B2-B0BE-1E1C63EF4C58}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal