Search results for 'LIFO'. 1 post(s) found.
- 2007/08/27 Stack Tutorial In C#
Stack is a LIFO (Last In First Out) queue, so if you add two items and then ask for an item you would get the second item then the first item. To add items to the Stack you use Push method. This method takes an object of any type but to keep things simple lets just give it a string object:
Stack s = new Stack();
s.Push("So");
s.Push("This");
s.Push("Is");
s.Push("How");
s.Push("Queues");
s.Push("Work");
s.Push("So");
s.Push("This");
s.Push("Is");
s.Push("How");
s.Push("Queues");
s.Push("Work");
Viewing a Single Object Without Removing it From the Stack
You can use the Peak method to get the bottom-most object in the Stack without removing it from the Stack:
Console.WriteLine(s.Peek());
Viewing All the Objects in the Stack Without Removing Them
You can read any of the data in the Stack by using an enumerator:
System.Collections.IEnumerator en = s.GetEnumerator();
while (en.MoveNext())
{
Console.Write(en.Current " ");
}
while (en.MoveNext())
{
Console.Write(en.Current " ");
}
Removing Items from the Stack
To Pop an item from the Stack you can use the Pop statement. This returns the bottom-most object of the Stack.
Another posts included in "C#"
| HashTable Tutorial In C# (0) | 2007/08/27 |
| Calling Your Main Thread From A Worker Thread In C# (0) | 2007/08/27 |
| Creating A Watched Folder With Assigned Events (0) | 2007/08/27 |
| Queue Tutorial In C# (0) | 2007/08/27 |
| Create PDF Files On the Fly In C Sharp (0) | 2007/08/27 |
| How to call Visual C/C++ implemented DLL functions in C# - Simple DLLIm... (0) | 2007/08/26 |
| Send Email Using C# (0) | 2007/08/26 |
| How To Read And Write A Cookie (0) | 2007/08/26 |
Trackback : Cannot send a trackbact to this post.
-
Subject By mail sale viagra.
2009/05/02 17:29
Viagra. Cheapest viagra. Buying overnight viagra. Re viagra cello.
-
Subject What are problems with prozac.
2009/05/22 14:02
Prozac menopause. Prozac dosage. What are problems with prozac. Prozac.
-
Subject different money making ideas
2010/01/29 05:42
moneyideas
-
Subject different money making ideas
2010/01/29 14:22
moneyideas
-
Subject different money making ideas
2010/01/31 16:44
moneyideas

Prev

Rss Feed