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)

True

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:

('cell',(x,y),['t','b','r','l']).

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)

0

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
Propositional versions of resolution: Just because of so far we've only looked at propositional versions of resolution. However in first-order logic we require to also deal wi

Binary Constraints: Alternatively unary constraints specify that a particular variable can take certain values that basically restricts the domain for that variable thus shoul

Digital switch It is a device that handles digital signals formed at or passed by a telephone company's central office and sends them across the company's backbone network.

Q. Illustrate the working of FLIP-FLOPS? A flip-flop is a binary cell that stores 1-bit of information. It itself is a sequential circuit. We know that flip-flop can change its

What is roll area? A roll area having the program's runtime context.  In addition to the runtime stack and other structures, all local variables and any data known to the prog

a) What do you meant by digital forensics? b) What is the job of Computer Forensic Analyst c) From the point of view of : i. An employer ii. An employee Give thre

What is an encoder? Draw the logic circuit of Decimal to BCD encoder and explain its working. Ans. Encoder: It is a combinational logic circuit which converts alphanumeric ch

Convert the following integers into their numerical equivalents in the indicated bases. Be sure to use the correct number of significant figures for each case and show how the corr

Q. Write a Menu driven program to convert the given Decimal number into Binary, Octal and Hexadecimal number. (Fractional numbers are allowed)

Solve the assignment of NFA-- Finite Automata and Formal Language Project Description: I have an assignment on Finite Automata and Formal Languages ( Nondeterministic Fini