12th Stack and Queue Assignments Year Wise - 24770469
12th Stack and Queue Assignments Year Wise - 24770469
A Circular Queue is a linear data structure which works on the principle of FIFO, enables
the user to enter data from the rear end and remove data from the front end with the rear
end connected to the front end to form a circular pattern.
Member functions:
void push(int n) : to add integer in the queue from the rear end if possible,
int pop() : removes and returns the integer from the front end of
(a) Specify the class Diary giving details of the functions void pushadd(String) and
String popadd( ). Assume that the other functions have been defined.
The main function and algorithm need NOT be written. [4]
(b) Name the entity used in the above data structure arrangement. [1]
JAVA MATLAB RAMJI SIR : 9305035029
Question 2018.
Register is an entity which can hold a maximum of 100 names. The register enables
the user to add and remove names from the top most end only.
Define a class Register with the following details:
Class name : Register
Data members / instance variables:
stud[ ] : array to store the names of the students
cap : stores the maximum capacity of the array
top : to point the index of the top end
Member functions:
Register (int max) : constructor to initialize the data member cap = max,
top = −1 and create the string array.
void push(String n) : to add names in the register at the top location if possible,
otherwise display the message “OVERFLOW”.
String pop( ) : removes and returns the names from the top most location
of the register if any, else returns “$$”.
void display( ) : displays all the names in the register
(a) Specify the class Register giving details of the functions void push(String) and
String pop( ). Assume that the other functions have been defined.
The main function and algorithm need NOT be written. [4]
(b) Name the entity used in the above data structure arrangement. [1]
JAVA MATLAB RAMJI SIR : 9305035029
Question 2017.
Queue is an entity which can hold a maximum of 100 integers. The queue enables
the user to add integers from the rear and remove integers from the front.
Define a class Queue with the following details: [5]
Class name : Queue
Data Members / instance variables:
Que[ ] : array to hold the integer elements
size : stores the size of the array
front : to point the index of the front
rear : to point the index of the rear
Member functions:
Queue (int mm) : constructor to initialize the data size = mm, front = 0,
rear = 0
void addele(int v ) : to add integer from the rear if possible else display the
message “Overflow” .
int delele( ) : returns elements from front if present, otherwise displays
the message “Underflow” and return -9999
void display ( ) : displays the array elements.
Specify the class Queue giving details of ONLY the functions void addele(int) and
int delele( ). Assume that the other functions have been defined.
The main function and algorithm need NOT be written.
JAVA MATLAB RAMJI SIR : 9305035029
Question 2016.
A bookshelf is designed to store the books in a stack with LIFO(Last In First Out)
operation. Define a class Book with the following specifications: [5]
Class name : Book
Data members/instance variables:
name[] : stores the names of the books
point : stores the index of the topmost book
max : stores the maximum capacity of the bookshelf
Methods/Member functions:
Book(int cap) : constructor to initialize the data members max = cap and
point = -1
void tell() : displays the name of the book which was last entered in the
shelf. If there is no book left in the shelf, displays the
message “SHELF EMPTY”.
void add(String v) : adds the name of the book to the shelf if possible, otherwise
displays the message ‘SHELF FULL”.
void display() : displays all the names of the books available on the shelf.
Specify the class Book giving the details of ONLY the functions void tell() and void
add(String). Assume that the other functions have been defined.
The main function need not be written.
JAVA MATLAB RAMJI SIR : 9305035029
Question 2015.
WordPile is an entity which can hold a maximum of 20 characters. The restriction is
that a character can be added or removed from one end only.
Some of the members of classes 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
Member functions/methods:
WordPile (int cap) : constructor to initialise 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”.
charpopChar() : returns the deleted character from the top of the WordPile
if possible, otherwise it returns ‘\\’
(a) Specify the class WordPile giving the details of the constructor, void
pushChar(char) and char popChar(). [8]
The main function and algorithm need not be written.
(b) What is the name of the entity described above and state one of its applications?
[2]
JAVA MATLAB RAMJI SIR : 9305035029
Question 2014.
A stack is a linear data structure which enables the user to add and remove integers
from one end only, using the concept of LIFO(Last In First Out). An array containing
the marks of 50 students in ascending order is to be pushed into the stack.
Define a class Array_to_Stack with the following details: [10]
Class name: Array_to_Stack
Data members/instance variables:
m[] : to store the marks
st[ ] : to store the stack elements
cap : maximum capacity of the array and stack
top : to point the index of the topmost element of the stack
Methods/Member functions:
Array_to_Stack(int n) : parameterized constructor to initialize cap = n and top = -1
void input_marks() : to input the marks from the user and store it in the array
m[ ] in ascending order and simultaneously push the marks
into the stack st[ ] by invoking the function pushmarks()
void pushmarks(int v) : to push the marks into the stack at top location if possible,
otherwise, display “not possible”
int popmarks() : to return marks from the stack if possible, otherwise,
return -999.
void display() : To display the stack elements
Specify the class Array_to_Stack, giving the details of the constructor(int), void
input_marks(), void pushmarks(int), int popmarks() and void display().
The main function and the algorithm need not be written.
JAVA MATLAB RAMJI SIR : 9305035029
Question 2013.
A doubly queue is a linear data structure which enables the user to add and remove
integers from either ends, i.e. from front or rear. Define a class Dequeue with the
following details: [10]
Specify the class Dequeue giving details of the constructor (int), void addfront(int),
void addrear (int, popfront ( ) and int poprear ( ). The main function and algorithm
need not be written.
JAVA MATLAB RAMJI SIR : 9305035029
Question 2012.
Link is an entity which can hold a maximum of 100 integers. Link enables the user to
add elements from the rear end and remove integers from the front end of the
entity. Define a class Link with the following details:
Class name : Link
Data Members/instance variables:
Ink [] : entity to hold the integer elements,
max : stores the maximum capacity of the entity,
begin : to point to the index of the front end.
end : to point to the index of the rear end.
Member functions:
Link(int mm) : constructor to initialize max = mm. begin = 0. end = 0.
void addlink (int v) : to add an element from the rear index if possible otherwise
display the message “OUT OF SIZE… ”
int dellink() : to remove and return an element from the front index. if
possible otherwise display the message “EMPTY …” and
return – 99.
void display() : displays the elements of the entity.
(a) Specify the class Link giving details of the constructor (int), void addlink (int), int
dellink() and void display ( ). [9]
THE MAIN FUNCTION AND ALGORITHM NEED NOT BE WRITTEN.
(b) What type of data structure is the above entity? [1]
JAVA MATLAB RAMJI SIR : 9305035029
Question 2011.
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.
(a) Specify class Stack giving details of the constructors(), void pushname(String n),
String popname() and void display(). [8] THE MAIN() FUNCTION AND ALGORITHM
NEED NOT BE WRITTEN.
(b) Under what Principle does the above entity work?
JAVA MATLAB RAMJI SIR : 9305035029
Question 2010.
Define a class Repeat which allows the user to add elements from one end (rear) and
remove elements from the other end (front) only.
The following details of the class Repeat are given below:
Class name : Repeat
Data Members/instance variables:
st[] : an array to hold a maximum of 100 integer elements
cap : stores the capacity of the array
f : to point the index of the front
r : to point the index of the rear
Member functions:
Repeat (int m) : constructor to initialize the data members cap = m, f = 0,
r = 0 and to create the integer array.
void pushvalue (int v) : to add integer from the rear index if possible else display the
message (“OVERFLOW”)
int popvalue () : to remove and return element from the front. If array is
empty then return -9999
void disp () : Displays the elements present in the list.
(a) Specify the class Repeat giving details of the constructor (int), member function
void pushvalue (int). int popvalue () and void disp (). The main ( ) function need not
be written. [8]
(b) What is the common name of the entity described above? [1]
(c) On what principle does this entity work? [1]
JAVA MATLAB RAMJI SIR : 9305035029
Question 2008.
NIC institute’s resource manager has decided to network the computer resources
like printer, storage media, etc. so that minimum resources and maximum sharing
could be availed. Accordingly printers are linked to a centralized system and the
printing jobs are done on a ‘first come first served basis, only. This is like the first
person’s printing job will get done first and the next person’s job will be done as the
next job in the list and so on. In order to avoid collision, the restriction is that no
more than 20 printing jobs can be added.
Define the class Printjob with the following details:
Class name : Printjob
Data members
job[] : array of integers to hold the printing jobs.
Newjob : to add a new printing job into the array.
Capacity : the maximum capacity of the integer array.
Front : to point out to the index of the front.
Rear : to point out to the index of the last.
Member functions
Printjob() : constructor to initialize data members.
Capacity=20, Front = Rear=-1 and call the function createJob().
void createJob() : to create an array to hold the printing jobs.
void addJob() : adds the new printing job to the end of the last printing job, if
possible, otherwise displays the message “Printjob is full, cannot
add any more”.
void removeJob() : Removes the printing job from the front if the printing job is not
empty, otherwise displays the message “Printjob is empty”.
a) Specify the class Printjob giving details of the constructor and the function void
addJob(), void createJob() and void removeJob() only. You do not need to write the
main function. [8]
b) What is the common name of the entity described above? [1]
c) State one of its applications [1]