C Programs Tutorials | IT Developer
IT Developer

Java Programs - Solved 2015 Theory Paper ISC Computer Science



Share with a Friend

Solved 2015 Theory Paper ISC Computer Science

Class 12 - ISC Computer Science Solved Theory Papers

WordPile Stack Program - ISC 2015 Theory

WordPile is an entity which can hold maximum of 20 characters. The restriction is that a character can be added or removed from one end only.

Some of the members of the class are given below:

Class name: WordPile
Data members/instance variables:
ch[]: character array to hold the character elements.
capacity: integer variable to store the maximum capacity.
top: to point to the index of the topmost element.

Methods/Member functions:
WordPile(int cap): constructor to initialize the data member capacity = cap, top = -1 and create the WordPile.
void pushChar(char v): adds the character to the top of WordPile if possible, otherwise output a message “WordPile is full”
char popChar(): returns the deleted character from the top of the WordPile if possible, otherwise it returns ‘\\’.

  1. Specify the class WordPile giving the details of the constructor, void pushChar(char) and char popChar(). The main function and algorithm need not be written.
  2. What is the name of the entity described above and state one of its applications.
class WordPile{ private char ch[]; private int capacity; private int top; public WordPile(int cap){ capacity = cap; if(capacity > 20) capacity = 20; top = -1; ch = new char[capacity]; } public void pushChar(char v){ if(top + 1 < capacity) ch[++top] = v; else System.out.println("WordPile is full"); } public char popChar(){ if(top == -1) return \'\\\'; else return ch[top--]; } }

Output

 
OUTPUT :

Answer: 2. The name of the entity described above is Stack. One of its applications is to reverse a string.