Function makestk-predicate function emptystk, Computer Engineering

1. Create the following ADTs.

(a) Write the constructor function makestk, predicate function emptystk and mutator functions pushstk and popstk:

i. makestk returns a new stack in the form of a tagged tuple: ('stack',[]).

e.g. >>> cellstk=makestk()

>>> cellstk

('stack', [])

ii. emptystk returns True or False depending on whether the given stack is empty or not.

e.g. >>> emptystk(cellstk)


iii. pushstk accepts a stack and an element, and adds the element to the stack at position 0 (see part (b) below for the creation of cell0).

e.g. >>> pushstk(cellstk,cell0)

>>> cellstk

('stack', [('cell', (0, 0), ['t', 'b', 'r', 'l'])])

iv. popstk removes the element at position 0 of the given stack.

e.g. >>> popstk(cellstk)

('cell', (0, 0), ['t', 'b', 'r', 'l'])

>>> cellstk

('stack', [])

(b) Write a constructor function called makecell, accessor functions getx, gety and getwalls, and mutator functions removetw, removebw, removerw, removelw.

i. makecell accepts a tuple which consists of the x and y co-ordinate of the cell being created. It returns a cell in the form of a tagged tuple:


The list represents the four walls of the cell: top, bottom, right and left.

e.g. >>> cell0=makecell((0,0))

>>> cell0

('cell', (0, 0), ['t', 'b', 'r', 'l'])

ii. getx and gety return the x and y co-ordinates (respectively) of a given cell.

e.g. >>> getx(cell0)


iii. getwalls returns the list of walls that are intact for a given cell

e.g. >>> getwalls(cell0)

['t', 'b', 'r', 'l']

iv. remove?w removes the associated wall from the list of walls of a given cell.

e.g. >>> removetw(cell0)

>>> cell0

('cell', (0, 0), ['b', 'r', 'l'])

Posted Date: 3/4/2013 7:32:13 AM | Location : United States

Related Discussions:- Function makestk-predicate function emptystk, Assignment Help, Ask Question on Function makestk-predicate function emptystk, Get Answer, Expert's Help, Function makestk-predicate function emptystk Discussions

Write discussion on Function makestk-predicate function emptystk
Your posts are moderated
Related Questions
Object Oriented Analysis and Design 1. What are the advantages of object-oriented systems? 2. Describe the Booch Methodology. 3. Justify that UML is a language for modeli

What are the Advantages of carrying out simulations -  saves cost (instead of doing the real thing) -  Safer (scenarios tried out on the simulation first before used in real

What is a half-adder? Explain a half-adder with the help of truth-table and logic diagram. Ans. Half Adder: It is a logic circuit for the addition of two 1-bit numbers is term

1. Write the function makegrid. This function accepts a width and height and creates a grid/matrix of cells. The width gives the number of columns and the height the number of rows

What is virtual memory? How address mapping is done in cache memory? Elaborate your answer with examples.

Q. Show the conflict in register? All micro-operations written on a line are to be executed at same time provided the statements or a group of statements to be implemented toge

What are the uses of interactive reporting? The user can actively control data retrieval and show during the session.  Instead of an extensive and detailed list, you make a ba

Design a 4-bit comparator using combinational logic, and Karnaugh Maps. The inputs of the circuit are two 2-bit numbers. a) Construct the truth table given 2-bits inputs A and B, a

Explain the role of a bus arbiter in a multiprocessor configuration. Bus arbiter: Which functions to resolve priority between bus masters and allows only one device at a time t