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 is the last entry in all BDC tables? In all BDC tables the last entry is to save the data by using the field name BDC_OKCODE and a field value of '/11'.

Suppose you work in a network security company, and you need to prepare a survey report of a particular security issue of wireless networking. To start with, select an area of wire

Explain the role that XML can play when dynamically generating HTML pages from a relational database? Ans) Even if student has never participated in a project involving this typ

Technology impact on job design - Information System The implementation of technology into work has had a significant impact on the types and content of job that are now avail

Q. How can we design Radio Button? Radio buttons are used when only one out of group of options is to be chosen. In the illustration code we have put a line break after every b

What is interaction modeling? Interaction model explains interactions within a system. The interaction model explains how objects interact to produce useful results. It is a ho

ARQ is transmitted in the event of: (A)  Loss of signal                          (B) Error in received data (C)  Improve reliability                  (D) During time out

a. Define the Key features of Hop field Neural Networks. b. Compare and contrast among Neural Networks and Expert systems in terms of knowledge representation, acquisition and e

Does it makes sense for two domain name servers to contain exactly the same set of names? Why? Yes. This is very advantageous for two domain servers having similar set of names

What are various IDs associated with a process? Unix identifies each process with a unique integer known as ProcessID. The process that implements the request for creation of a