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

What is shared memory programming, Q. What is Shared Memory Programming? ...

Q. What is Shared Memory Programming? We know all processors share a common memory in shared memory model. Every processor can be assigned a separate portion of program stored

Computer network architecture, A protocol is a formal description of messag...

A protocol is a formal description of message formats and the rules two or more machines must follow to exchange those messages. Because TCP (transmission control protocol) and IP

Can we convert the column data into row data, We download data which arrive...

We download data which arrives to me in a column. I need to use it in a complex sheet that requires data in a row. How can we convert the column data into row data?   Ans) H

Illustrates several names of popular internet browsers, Illustrates several...

Illustrates several names of popular internet browsers? Popular Internet Browsers are: Internet Explorer, Netscape Navigator and Mosaic, Google chrome and Mozilla and Opera.

Explain anonymous FTP, Explain Anonymous FTP. Use of a login password...

Explain Anonymous FTP. Use of a login password and name helps maintain file secure from unauthorized access. Though, sometimes these authorizations can also be inconvenient.

Implement and - or- not gates using bit wise operator, Q. Develop  a menu d...

Q. Develop  a menu driven program to implement AND, OR, NOT gates using and without using  Bit wise operator. The menu  should  be  as follows: I.  Using Bit Wise operator I

State the concept of multiplicity, Multiplicity Multiplicity in an ass...

Multiplicity Multiplicity in an association specifies tells us about number of objects participate in a relationship. It decides the number of related objects. Multiplicity is

Id3 algorithm, ID3 algorithm: Further for the calculation for informat...

ID3 algorithm: Further for the calculation for information gain is the most difficult part of this algorithm. Hence ID3 performs a search whereby the search states are decisio

what are the advantages of threads over processes, What are the advantages...

What are the advantages of threads over processes? Some of the useful threads offer over processes includes: i)   It does not take more time to create and finished a new thr

Accept commands from the user, Your shell must accept commands from the use...

Your shell must accept commands from the user. The first step to implement this will be reading a line of input. This section will focus on what to do with the line of input after

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