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
What are the special unit related fields and methods?   The most significant method (in fact pseudo method) related to units is get_enclosing_unit().  The mostly used field in

Q.Joint Application Development session leader? JAD session leader: JAD leader organizes and runs the JAD. This person is trained in group management and facilitation as well

"Super ASCII", if it contains the character frequency equal to their ascii values. String will contain only lower case alphabets (''a''-''z'') and the ascii values will starts from

Q. Convert the following from hexadecimal to binary, decimal, BCD and octal. a) 111 b) ABC.25 c) 2.C Q. Convert the following from BCD to binary, decimal, hexadecimal an

Different EDI components and services  Three main components containing services in EDI System are as follows:  •  Application Service: Gives the means of integrating existi

Q. What is Presentation layer? Presentation layer: When two hosts are communicating with each other they might use different coding standards and character sets for represent

Will case infer priority register if yes how give an example? Yes case can infer priority register depending on coding style reg r; // Priority encoded mux, always @

What are User threads   User threads are supported above the kernel and are executed by a thread library at the user level. Thread creation & scheduling are done in the user sp

haw to convert context free grammar to regular grammar

Perform the 23 - 48 operations using the 2's complement method. Ans. Given 23 - 48 firstly add them       23                         0 1 0 1 1 1 - (- 48)                     +