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
List the key notions concerning macro expansion. Two key notions relating to macro expansion is: 1. Expansion time control flow- Determines the order of model statements tha

Calculate the maximum access time that can be permitted for the data and control memories in a TSI switch with a single input and single output trunk multiplexing 2500 channels. Al

Explain What is the difference among embedded systems and the system in which RTOS is running? Ans) Embedded system can have RTOS and cannot have also. It depends on the requi

What are the advantages of using structure in C Program Declaring a struct is a two-stage process. The first stage defines a new data type that has the required structure which

Disadvantages of MPI  Performance is restricted by communication network between the nodes It can be harder to debug Needs more programming changes to go from seri

(a)  Explain in a few sentences the difference between a natural frequency and a resonant frequency.  Also clarify why for a specific system or component these frequencies may diff

Define variants of Turing Machine?  Variants are  Non deterministic turing machine.  Mutlitape turing  machine.  Enumerators

1. Figure 1 below shows the truth table for five different functions. Each truth table shows the inputs x1, x2 and the desired output d. (a) Write down which of these functions


Memory-to-Memory Architecture The pipelines can access vector operands intermediate and final results straight in main memory. This necessitates the higher memory bandwidth. Fu