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

Write a program to find the area and perimeter of a circle, Write a program...

Write a program to find the area and perimeter of a circle of given radius # include void main() { float radius, area, perimeter, pi=3.14; printf("\nEnter the rad

How does bus arbitration typically work, How does bus arbitration typically...

How does bus arbitration typically work? i.  A bus master waiting to use the bus asserts by  the bus request. ii.  A bus master cannot be the bus until it's request is grant

Define radix base, Define Radix (or)Base. A number system of base or ra...

Define Radix (or)Base. A number system of base or radix is a system that uses different symbols for r digits. Numbers are shown by a string of digit symbols. To verify the quan

Fundamental components of a CPU, Q. Fundamental components of a CPU? Th...

Q. Fundamental components of a CPU? The two fundamental components of a CPU are control unit and arithmetic and logic unit. The control unit of CPU selects and interprets progr

Which data structures used in language processing, Which structure can be u...

Which structure can be used as a criterion for classification of data structures used in language processing. And. Nature of a data structure, purpose of a data structure and l

Criteria for selecting a theme for a project, Q. Criteria for selecting a t...

Q. Criteria for selecting a theme for a project? Topics for projects as we indicated earlier should emerge from the children's world. Teaching often becomes boring and unintere

What is busy hour traffic, Busy hour traffic is the (A)  maximum avera...

Busy hour traffic is the (A)  maximum average simultaneous traffic. (B)  traffic during peak hour. (C)  traffic when all subscribers are engaged. (D)  the durat

What is hybrid olap, When a database developer uses Hybrid OLAP it seperate...

When a database developer uses Hybrid OLAP it seperates the data among relational and specialized storage. In some certain modifications a HOLAP database may store vast amounts of

What is double data rate sdram, What is double data rate SDRAM?  Double...

What is double data rate SDRAM?  Double data rates SDRAM are those which can transfer data on both edges of the clock and their bandwidth is fundamentally doubled for long burs

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