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
Explain advantageand disadvantages of a dynamic document.   The chief advantages of a dynamic document lie in its capability to report current information. For illustratio

Give an account of modems used in data transfer. Modem: Modems are usually provided through network operators (Department of Telecommunication in India) or through vendors wh

create a BCD adder combinational ckt. that adds 2 digit BCD inputs

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

Q. Major problems associated in writing with cache memories? The data in main and cache memory can be written by processors or I/O devices. The major problems associated in wri

Bitwise Operators Like  other  operators  bitwise  operators  have  rules  of  precedence  and  associativity  that determine how expressions involved them are evaluated.

Describe the various characteristics of UDP protocol. The characteristics of the UDP are as follows: End to end: UDP is transport protocols that can distinguish between

BIOS or Basic Input/Output System is the first program accessed by the processor during start up to make sure that all the other basic programs, hard drives, ports, peripherals and

Explain a binary semaphore with the help of an example? An abstract data type (ADT) is a semaphore which defines a nonnegative integer variable that apart from initialization i

What is random access memory(RAM or MAIN MEMORY) and mention its types? The main memory in the central storage unit in a computer system. It is relatively large and fast memory