Given a partial main.py and PlaneQueue class in PlaneQueue.py, write the push() and pop() methods for PlaneQueue. Then complete main.py to read in whether flights are arriving or have landed at an airport. An "arriving" flight is pushed onto the queue. A "landed" flight is popped from the front of the queue. Output the queue after each plane is pushed or popped. Entering -1 exits the program. Ex: If the input is:   arriving AA213 arriving DAL23 arriving UA628 landed -1   the output is: (see image attached)     main.py from PlaneQueue import PlaneQueue from PlaneNode import PlaneNode   if __name__ == "__main__":   plane_queue = PlaneQueue()       # TODO: Read in arriving flight codes and whether a flight has landed.    #    Print the queue after every push() or pop() operation. If the user   #    entered "landed", print which flight has landed. Continue until -1    #    is read.   PlaneNode.py class PlaneNode:   def __init__(self, flight_code='0'):     self.flight_code = flight_code     self.next = None         def print_node_data(self):     print(self.flight_code, end='')   PlaneList.py class PlaneList:   def __init__(self):     self.head = None     self.tail = None     def append(self, new_node):     if self.head == None:       self.head = new_node       self.tail = new_node     else:       self.tail.next = new_node       self.tail = new_node     def prepend(self, new_node):     if self.head == None:       self.head = new_node       self.tail = new_node     else:       new_node.next = self.head       self.head = new_node     def insert_after(self, current_node, new_node):     if self.head == None:       self.head = new_node       self.tail = new_node     elif current_node is self.tail:       self.tail.next = new_node       self.tail = new_node     else:       new_node.next = current_node.next       current_node.next = new_node           def remove_after(self, current_node):     # Special case, remove head     if (current_node == None) and (self.head != None):       succeeding_node = self.head.next       self.head = succeeding_node         if succeeding_node == None: # Remove last item         self.tail = None     elif current_node.next != None:       succeeding_node = current_node.next.next       current_node.next = succeeding_node       if succeeding_node == None: # Remove tail         self.tail = current_node     def search(self, key):     position = 1     cur_node = self.head     while cur_node != None:       if cur_node.data == key:         cur_node.node_pos = position         return cur_node       cur_node = cur_node.next       position += 1       def print_list(self):     cur_node = self.head     while cur_node != None:       cur_node.print_node_data()       print()       cur_node = cur_node.next   PlanbeQueue.py from PlaneList import PlaneList   class PlaneQueue:   def __init__(self):     self.plane_list = PlaneList()     self.length = 0       # TODO: Write push() and pop() methods. push() adds an item to the queue   #    and adds 1 to length. pop() removes and returns the first item in    #    the queue and subtracts 1 from length.       def is_empty(self):     return self.length == 0         def print_queue(self):     print('Air-traffic control queue')     if not self.is_empty():       print('  Next to land:', end=' ')       cur_node = self.plane_list.head       cur_node.print_node_data()       print()               if self.length > 1:         print('  Arriving flights:')         cur_node = cur_node.next         while cur_node is not None:           print('   ', end='')           cur_node.print_node_data()           print()           cur_node = cur_node.next     else:       print('Queue is empty.')     print()

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Given a partial main.py and PlaneQueue class in PlaneQueue.py, write the push() and pop() methods for PlaneQueue. Then complete main.py to read in whether flights are arriving or have landed at an airport.

  • An "arriving" flight is pushed onto the queue.
  • A "landed" flight is popped from the front of the queue.

Output the queue after each plane is pushed or popped. Entering -1 exits the program.

Ex: If the input is:

 

arriving AA213

arriving DAL23

arriving UA628

landed

-1

 

the output is: (see image attached)

 

 

main.py

from PlaneQueue import PlaneQueue

from PlaneNode import PlaneNode

 

if __name__ == "__main__":

  plane_queue = PlaneQueue()

   

  # TODO: Read in arriving flight codes and whether a flight has landed. 

  #    Print the queue after every push() or pop() operation. If the user

  #    entered "landed", print which flight has landed. Continue until -1 

  #    is read.

 

PlaneNode.py

class PlaneNode:

  def __init__(self, flight_code='0'):

    self.flight_code = flight_code

    self.next = None

     

  def print_node_data(self):

    print(self.flight_code, end='')

 

PlaneList.py

class PlaneList:

  def __init__(self):

    self.head = None

    self.tail = None

 

  def append(self, new_node):

    if self.head == None:

      self.head = new_node

      self.tail = new_node

    else:

      self.tail.next = new_node

      self.tail = new_node

 

  def prepend(self, new_node):

    if self.head == None:

      self.head = new_node

      self.tail = new_node

    else:

      new_node.next = self.head

      self.head = new_node

 

  def insert_after(self, current_node, new_node):

    if self.head == None:

      self.head = new_node

      self.tail = new_node

    elif current_node is self.tail:

      self.tail.next = new_node

      self.tail = new_node

    else:

      new_node.next = current_node.next

      current_node.next = new_node

       

  def remove_after(self, current_node):

    # Special case, remove head

    if (current_node == None) and (self.head != None):

      succeeding_node = self.head.next

      self.head = succeeding_node  

      if succeeding_node == None: # Remove last item

        self.tail = None

    elif current_node.next != None:

      succeeding_node = current_node.next.next

      current_node.next = succeeding_node

      if succeeding_node == None: # Remove tail

        self.tail = current_node

 

  def search(self, key):

    position = 1

    cur_node = self.head

    while cur_node != None:

      if cur_node.data == key:

        cur_node.node_pos = position

        return cur_node

      cur_node = cur_node.next

      position += 1

   

  def print_list(self):

    cur_node = self.head

    while cur_node != None:

      cur_node.print_node_data()

      print()

      cur_node = cur_node.next

 

PlanbeQueue.py

from PlaneList import PlaneList

 

class PlaneQueue:

  def __init__(self):

    self.plane_list = PlaneList()

    self.length = 0

   

  # TODO: Write push() and pop() methods. push() adds an item to the queue

  #    and adds 1 to length. pop() removes and returns the first item in 

  #    the queue and subtracts 1 from length.

 

 

  def is_empty(self):

    return self.length == 0

     

  def print_queue(self):

    print('Air-traffic control queue')

    if not self.is_empty():

      print('  Next to land:', end=' ')

      cur_node = self.plane_list.head

      cur_node.print_node_data()

      print()

       

      if self.length > 1:

        print('  Arriving flights:')

        cur_node = cur_node.next

        while cur_node is not None:

          print('   ', end='')

          cur_node.print_node_data()

          print()

          cur_node = cur_node.next

    else:

      print('Queue is empty.')

    print()

Air-traffic control queue
Next to land: AA213
Air-traffic control queue
Next to land: AA213
Arriving flights:
DAL23
Air-traffic control queue
Next to land: AA213
Arriving flights:
DAL23
UA628
AA213 has landed.
Air-traffic control queue
Next to land: DAL23
Arriving flights:
UA628
Transcribed Image Text:Air-traffic control queue Next to land: AA213 Air-traffic control queue Next to land: AA213 Arriving flights: DAL23 Air-traffic control queue Next to land: AA213 Arriving flights: DAL23 UA628 AA213 has landed. Air-traffic control queue Next to land: DAL23 Arriving flights: UA628
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY