Stack Implementation Using Arrays | Explained in Tamil

  Рет қаралды 11,527

CSE Teacher

3 жыл бұрын

#define MAX 3
int stack[MAX];
int top=-1;
void push(int num)
{
if(top==MAX-1)
{
printf("
Stack Overflows");
}
else
{
top++;
stack[top]=num;
}
}
void pop()
{
if(top==-1)
{
printf("
Stack Underflows");
}
else
{
printf("
Poped element is %d",stack[top]);
top--;
}
}
void peek()
{
if(top==-1)
printf("
Stack Underflows");
else
printf("
Top element is %d",stack[top]);
}
void display()
{
if(top==-1)
printf("
Stack is empty");
else
{
int i;
printf("
Elements in the stack:");
for(i=0;ilessthan=top;i++)
printf("\t%d",stack[i]);
}
}
int main()
{
int choice,num;
printf("
\t STACK OPERATIONS USING ARRAY");
printf("
\t--------------------------------");
printf("
\t 1.PUSH
\t 2.POP
\t 3.TOP
\t 4.DISPLAY
\t 5.EXIT");
do
{
printf("

Enter the Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("
Enter the element to push: ");
scanf("%d",&num);
push(num);
display();
break;
case 2:
pop();
display();
break;
case 3:
peek();
break;
case 4:
display();
break;
case 5:
printf("
\t EXIT POINT ");
break;
default:
printf ("
\t Please Enter a Valid Choice");
break;
}
}
while(choice!=5);
return 0;
}
/*int isFull()
{
if(top==MAX-1)
return 1;
else
return 0;
}
int isEmpty()
{
if top==-1)
return 1;
else
return 0;
}
*/

Пікірлер: 5
@kindheartedone8880
@kindheartedone8880 Жыл бұрын
had watched 6 to 7 best youtubers videos which till now i followed but clear explanation from base have a bright future in teaching profession mam ❤
@SangeethaP-sm7lb
@SangeethaP-sm7lb 9 ай бұрын
Super mam
@animeshorts957
@animeshorts957 Жыл бұрын
Tq akka
@rubeshrubesh5684
@rubeshrubesh5684 2 жыл бұрын
Mam doubt
@Sandypallavihemanth
@Sandypallavihemanth Жыл бұрын
What doubt dr......
MY HEIGHT vs MrBEAST CREW 🙈📏
00:22
Celine Dept
Рет қаралды 27 МЛН
Synyptas 4 | Арамызда бір сатқын бар ! | 4 Bolim
17:24
Ozoda - Lada ( Official Music Video 2024 )
06:07
Ozoda
Рет қаралды 30 МЛН
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 32 МЛН
MY HEIGHT vs MrBEAST CREW 🙈📏
00:22
Celine Dept
Рет қаралды 27 МЛН