Last active
October 2, 2016 00:57
-
-
Save Abiwax/045fbc285a4acdf0baa9905a056bb8d2 to your computer and use it in GitHub Desktop.
Data Structures
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
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
//Array | |
/*int[] java = new int[] { 70, 88, 30 }; | |
//Array.Sort(java); | |
foreach(int i in java){ | |
Console.WriteLine(i); | |
} | |
*/ | |
//ArrayList | |
/* | |
ArrayList myArray = new ArrayList(); | |
myArray.Add("Abisola"); | |
myArray.Add("Java"); | |
myArray.Add("Apple"); | |
myArray.Add(10); | |
myArray.Add(33); | |
myArray.Add(56); | |
myArray.Add(12); | |
myArray.Add(23); | |
//myArray.Sort(); | |
Console.WriteLine("myArray has {0} Capacity", myArray.Capacity); | |
Console.WriteLine("myArray has {0} Element", myArray.Count); | |
myArray.RemoveAt(3); | |
Console.WriteLine("\nThe elements in my array are:"); | |
foreach (object j in myArray){ | |
Console.WriteLine(j); | |
} | |
myArray.Reverse(); | |
myArray.Insert(3, 10); | |
Console.WriteLine("\nReversed list with additonal element"); | |
foreach (object j in myArray){ | |
Console.WriteLine(j); | |
} | |
int[] statistics = new int[] { 76, 40, 90 }; | |
foreach(int j in statistics){ | |
myArray.Add(j); | |
} | |
myArray.AddRange(java); | |
Console.WriteLine("\n"); | |
foreach (object j in myArray){ | |
Console.WriteLine(j); | |
} | |
Console.WriteLine("\nPrint out only strings"); | |
foreach (object u in myArray){ | |
if (u is string){ | |
Console.WriteLine("I am a String: {0}", u); | |
} | |
} | |
*/ | |
//List | |
/* | |
List<int> myList = new List<int>(); | |
myList.Add(78); | |
myList.Add(95); | |
myList.Add(23); | |
myList.Add(15); | |
myList.Add(23); | |
Console.WriteLine("\nMy new List"); | |
foreach(int i in myList){ | |
Console.WriteLine(i); | |
} | |
myList.Sort(); | |
Console.WriteLine("\nMy sorted List"); | |
foreach(int i in myList){ | |
Console.WriteLine(i); | |
} | |
Console.WriteLine("\nMy List Sum is: "+ myList.Sum()); | |
Console.WriteLine("\nMy Distinct List contains: "); | |
List<int> newList = myList.Distinct().ToList(); | |
foreach(int i in newList){ | |
Console.WriteLine(i); | |
} | |
*/ | |
//Linked List | |
/* | |
LinkedList<string> myLink = new LinkedList<string>(); | |
myLink.AddLast("Stephen"); | |
myLink.AddLast("Hatem"); | |
myLink.AddLast("Emmanuel"); | |
myLink.AddFirst("Gordon"); | |
Console.WriteLine("My Linked List contains"); | |
foreach (var i in myLink) | |
{ | |
Console.WriteLine(i); | |
} | |
*/ | |
//Dictionary | |
/* | |
Dictionary<string, int> myDictionary = new Dictionary<string, int>(); | |
myDictionary.Add("Age", 25); | |
myDictionary.Add("Grade", 80); | |
Console.WriteLine("\nAge is {0}", myDictionary["Age"]); | |
List<string> myKey = new List<string>(myDictionary.Keys); | |
for (int i = 0; i < myKey.Count; i++) | |
{ | |
int myInt = myDictionary[myKey[i]]; | |
Console.WriteLine(myInt); | |
} | |
*/ | |
//Hastable | |
/* | |
Hashtable myHash = new Hashtable(); | |
myHash["Name"] = "Abisola"; | |
myHash[1] = "Name"; | |
myHash[3] = "is"; | |
myHash[2] = "my"; | |
//myHash.Add("Grade", 80); | |
Console.WriteLine("Hashtable contains {0} elements \nAnd they are: ", myHash.Count); | |
foreach (DictionaryEntry entry in myHash) | |
{ | |
Console.WriteLine("{0}, {1}", entry.Key, entry.Value); | |
} | |
for (int i = 0; i < myHash.Count; i++){ | |
Console.WriteLine("My Index is "+ i); | |
Console.WriteLine("And i contain: "+ myHash[i]); | |
} | |
*/ | |
//Stack | |
/* | |
Declaration types | |
Stack myStack = new Stack(); | |
Stack<string> myStack = new Stack<string>(); | |
*/ | |
/* | |
Stack<string> myStack = new Stack<string>(); | |
myStack.Push("Chanel"); | |
myStack.Push("Prada"); | |
myStack.Push("Gucci"); | |
Console.WriteLine(); | |
Console.WriteLine("My Top Value is "+myStack.Peek()); | |
Console.WriteLine(); | |
Console.WriteLine(myStack.Pop()); | |
Console.WriteLine(); | |
Console.WriteLine("My Top Value is "+myStack.Peek()+"\n"); | |
foreach(string s in myStack) | |
{ | |
Console.WriteLine(s); | |
} | |
*/ | |
/* | |
Stack myStack = new Stack(); | |
myStack.Push("Chanel"); | |
myStack.Push("Prada"); | |
myStack.Push("Gucci"); | |
Console.WriteLine(); | |
Console.WriteLine("My Top Value is "+myStack.Peek()); | |
Console.WriteLine(); | |
Console.WriteLine(myStack.Pop()); | |
Console.WriteLine(); | |
Console.WriteLine("My Top Value is "+myStack.Peek()); | |
*/ | |
//Queue | |
/* | |
Queue<int> myQueue = new Queue<int>(); | |
myQueue.Enqueue(5); | |
myQueue.Enqueue(10); | |
myQueue.Enqueue(15); | |
myQueue.Enqueue(20); | |
foreach (int i in myQueue) | |
{ | |
Console.WriteLine(i); | |
} | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment