Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
7.3k views
in Computer by (49.9k points)
closed by

A stack is a kind of data structure which can store elements with the restriction that an element can be added or removed from the top only. 

The details of the class Stack is given below: 

Class name: Stack 

Data members/instance variables: 

st[]: the array to hold the names 

size: the maximum capacity of the string array 

top: the index of the topmost element of the stack

ctr: to count the number of elements of the stack Member functions: 

Stack( ): default constructor 

Stack(int cap): constructor to initialize size = cap and top = -1 

void pushname(String n): to push a name onto the stack. If the stack is full, display 

the message “OVERFLOW” 

String popname(): removes a name from the top of the stack and returns it. 

If the stack is empty, display the message “UNDERFLOW” 

void display(): Display the elements of the stack

Specify class Stack giving details of the constructors(), void pushname(String n), String popname() and void display().

THE MAIN() FUNCTION AND ALGORITHM NEED NOT BE WRITTEN.

1 Answer

+3 votes
by (49.0k points)
selected by
 
Best answer

Class Stack 

String ST [ ]; 

int size; 

int top; 

int etr; 

Stack( ) 

for(int i = 0; 

i <10; i++) St [i] = " "; 

size = 0; 

top = 0; 

ctr = 0; 

Stack(int cap) 

size = cap 

St [size];

top = -1 ; 

void pushname (String n) 

if (top = = (size - 1)) 

System.out.println (''overflow''); 

else 

top ++; 

St [top] = n;

}

String popname( ) 

String v; 

if(top = = -1) 

System.out.println(''underflow "); 

else 

{ v = St[top]; 

System.out.println("poped element is''+'' : " + v); 

top--; 

void display 

if(top == -1) 

System.out.println(''empty''); 

else 

{

for (int i = top-1; i > = 0 ; i--) 

System.out.println(St [i]): 

}

by (10 points)
Thank you

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...