Question

Test ADTs: Linked Lists, Stacks and Queues (Python and with proper indentation for better understanding please)....

Test ADTs: Linked Lists, Stacks and Queues (Python and with proper indentation for better understanding please).

  1. Create a program that will choose 30 objects with an attribute of random number between 1 and 100.
  2. Place each object it in a queue.
  3. From that each object will exit the queue in the order that it entered two waiting stacks.
  4. Sort those stacks and create two doubly circular linked lists from those stacks.
  5. Merge those lists into one doubly circular linked list.
  6. Comment your code documenting each of the above numbered items (2-5).
  7. Create a flow chart of your code.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER:

GIVEN THAT:

Stacks: objects can be pushed in and popped out at any time

implementing a stack in python:

class IsEmptyError(exception):

pass

class sllstack:

class node;

def_init_(self, element, _next)

self.element =element

self._next=_next

def_inti_(self);

self.head=none

self.size=0

def_len_(self);

return self.size

def_is_empty(self)

return self.size==0

def push(self,element);

self.head= self.node(element,self.head)\

self.size==1

def pop(self);

if selft.is empty();

raise Is emptyerror(' this stack is empty ')

result = self.head.element

self.head=self.head._next

self.size==1

return result

def top(self);

if self.is_empty();

raise isemptyerror('stack is empty, retrive any element')

retrurn.head.e;element

implementation of queue:

  • class Isemptyerror(exception);
  • pass
  • class sllqueue;
  • class node;
  • def_inti_(self, element,_next);
  • self.element=element;
  • self.next= _next;
  • def_init_(self);
  • self.head=none
  • self.tail=none
  • self.size=0
  • def_len_(size);
  • return self.size==0
  • def enqueue(self,element);
  • new=self.node(element,none)
  • if self.is_empty();
  • self.head=new
  • else:
  • self.tail_next=new
  • self.tail =new
  • self.size=1
  • def.dequeue(self);
  • if self.is_empty();
  • raise isemptyerror('empty queue, so cannot dequeue');
  • result= self.head.element
  • self.head=self.head_next
  • self.size==1
  • if self.is_empty();
  • self.tail=none
  • return result;
  • def first (self);
  • raise isempty_error('queue is empty, so cannot return')
  • return self.head.element;
Add a comment
Know the answer?
Add Answer to:
Test ADTs: Linked Lists, Stacks and Queues (Python and with proper indentation for better understanding please)....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT