Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
custom stack Implementation
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Rextester { public class Program { public static void Main(string[] args) { //custom stack Implementation myStack st = new myStack(); st.Push(2); st.Push(4); st.Push(6); st.Push(8); st.printStack(); st.Pop(); st.Pop(); st.printStack(); } } public class myStack { private int indx; private ArrayList list; public myStack() { list = new ArrayList(); indx = -1; } public int count { get { return list.Count; } } public void Push(object item) { list.Add(item); indx++; } public object Pop() { object obj = list[indx]; list.RemoveAt(indx); indx--; return obj; } public void clear() { list.Clear(); indx = -1; } public object peek() { return list[indx]; } public void printStack(){ Console.WriteLine("\n Stack elements"); foreach (int i in list) { Console.WriteLine(i); } Console.WriteLine("Number of elements in the stack " + count ); Console.WriteLine("Does stack contain the number 6 "+list.Contains(6)); } } }
run
|
edit
|
history
|
help
0
Zadanka
contraseña
Table of 3 and 5 using threads
multiplyarr
asxs
codetility CyclicRotation
Remove Duplicate characters from String
z x xc x
LINQ Collections
Select, Foreach and Exceptions in C#