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
Computer Architecture Basics: Some of computer architecture at companies such like AMD and Intel uses more fine distinctions: Macro architecture- this is an architectura

The hybrid models are mostly tailormade models suiting to exact applications. Actually these fall in the category of mixed models. Such type of application-oriented models keep cro

The conflict between too hot and too cold or too slow and too fast can be resolved using don't care states. Don't care states are used when i) the state of the output is not

Optimum solution based on constraint problems: Whether depending on what solver you are using so there constraints are often expressed as relationships between variables as e.

Give difference between assembler and compiler. Assembler: It is the translator for an assembly language of computer. An assembly language is a low-level programming language

Are there any special rules about inlining? Yes, there are some rules about inlining - a.) Any source files which used inline function should contain function's definition.

How is a multidimensional array defined in terms of a pointer to a collection of contiguous arrays of lower dimensionality ? C does not have true multidimensional arrays. Howev

Q. Describe buffer of receiving process? MPI_Gather (Sendaddr, Scount, Sdatatype, Receiveaddr, Rcount, Rdatatype,Rank, Comm): 'Using this function process with rank' rank

A persistent cookie is a cookie which is keeps in a cookie file permanently on the browser's computer. By default, cookies are formed as temporary cookies which keep only in the br

Write notes on Frame Filtering Techniques. Frame filtering: The most valuable function performed through bridges is frame filtering. A bridge doesn't forward a frame unles