Learn Computer Science programming - C# and C++ Algorithms

 
C# Stack-based array

Code
c_stack_based_array.zip
File Size: 22 kb
File Type: zip
Download File

using System;


namespace LinkedList
{
/// <summary>
/// Summary description for Stack2.
/// </summary>
public class Stack2
{
public int[] items = new int [10];


public void Push (int data, int i)
{
items[i] = data;
}
public int Pop(int x)
{
return x;
}
}


public class MainClass
{
static void Main ()
{
Stack2 stack = new Stack2 ();

//PUSH
for (int i=0; i < stack.items.Length ; i++)
{
stack.Push (i+ 10,i);
}


//POP
for (int i=0; i <stack.items.Length; i++ )
{
int x = stack.Pop (stack.items [i]);
Console.WriteLine (x);
}
Console.WriteLine ("Press any key...");
Console.ReadLine ();
}
}
}