0% found this document useful (0 votes)
4 views4 pages

C# Stack Operations Implementation

The document describes a C# program to implement stack operations. It defines a Stack class with methods to insert elements, pop (remove) elements, and display the current elements. The Main method contains a menu loop that allows the user to insert elements, pop elements, display the stack, or quit the program by selecting the corresponding menu options.

Uploaded by

digantasahariah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

C# Stack Operations Implementation

The document describes a C# program to implement stack operations. It defines a Stack class with methods to insert elements, pop (remove) elements, and display the current elements. The Main method contains a menu loop that allows the user to insert elements, pop elements, display the stack, or quit the program by selecting the corresponding menu options.

Uploaded by

digantasahariah
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

5.

Write a program to impement Stack Operations in C#

using System;
using [Link];
using [Link];

namespace LABPROGRAMS
{

class stack
{
int i, max, top;
int[] a = new int[10];
public stack()
{
top = -1;
max = 5;
}

//Inserting an elements into the stack


public void insert(int item)
{
//[Link]("top={0}", top);
if (top == (max - 1))
{
[Link]("stack is overflow");
return;
}
else
top++;
a[top] = item;

1
5. Stack Operations : continuation

//Deleting an elements from the stack


public void pop()
{
if (top == -1)
{
[Link]("stack is underflow");
return;
}
else
[Link]("The popped elements are:{0}\t", a[top]);
top--;

//Displaying the current elements from the stack


public void display()
{
if (top == -1)
{
[Link]("stack is underflow");
return;
}
[Link]("The elements in the stack are:");
for (i = 0; i <= top; i++)
{
[Link]("{0}\t", a[i]);
}
}
}

2
5. Stack Operations : continuation

class stack1
{
static void Main(string[] args)
{
stack s = new stack();
int choice, n;
[Link]("PROGRAM TO IMPLEMENT STACK OPERATIONS");
do
{
[Link]("\n\[Link]");
[Link]("[Link]");
[Link]("[Link]");
[Link]("[Link]");
[Link]("Enter your choice");
choice = [Link]([Link]());
switch (choice)
{
case 1:

[Link]("Enter the value to insert in the stack");


n = [Link]([Link]());
[Link](n);
break;
case 2:
[Link]();
break;
case 3:
[Link]();
break;
case 4:
[Link]("you are exited");
[Link]();
[Link](0);
break;
default:
[Link]("Enter valid choice");
break;
}
} while (choice!= 4);

}
}
}

3
4

You might also like