Function makestk-predicate function emptystk, Computer Engineering

Assignment Help:

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'])


Related Discussions:- Function makestk-predicate function emptystk

Connection machine fortran, Q. Connection Machine FORTRAN? Connection M...

Q. Connection Machine FORTRAN? Connection Machine Fortran was a subsequent SIMD language developed by Thinking Machines Corporation. Connection Machine Fortran incorporated all

Differences between internal and external fragmentation, Explain the differ...

Explain the differences between Internal and external fragmentation. Internal and external fragmentation (1) While memory allocated to a process is a little larger than th

What is difference between hold time and setup, What is difference between ...

What is difference between hold time and setup? The interviewer was looking for one exact reason, and it’s really a good answer as well..The hint is hold time doesn't depend onto c

Error handling in hard disk, Error handling in Hard disk in computer archit...

Error handling in Hard disk in computer architecture : Modern drives also make widespread use of Error Correcting Codes (ECCs), specifically Reed-Solomon error correction.

Explain simplifying the sop boolean expression using k-map, Explain Simplif...

Explain Simplifying the SOP f the Boolean expression using the K-Map? To simplify the SOP of the Boolean expression using the K map, first identify all the input combinations tha

Experiment with neural network, Assignment 3.b: Experiment with Neural Netw...

Assignment 3.b: Experiment with Neural Network Background: In this assignment, you will experiment with neural network for solving different types of practical problems. Y

Explain about combinational circuits, Q. Explain about Combinational Circui...

Q. Explain about Combinational Circuits? Combinational Circuit is one of the models for parallel computers. In interconnection networks, different processors correspond with ea

Boundary tag management system, what are the two memory management scehme...

what are the two memory management scehme(boundary tag system,buddy system)

Example of circuit switching & stored and forward switching, Example of cir...

Example of circuit switching and S&F (Stored and Forward) switching is (A) Telephone and Post of Telegraph (B) Video Signal Post or Telegraph (C)  Digital Signal P

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd