Professional Documents
Culture Documents
EE207-Data Structure
Semester: spring 2022
Section No.
Student Name:
Student Id:
2171115598 / 2171119343
Date: May30th,2022
Why do we used linked list?
A Singly Linked List consists of Nodes attached to each other where each node has two members – ‘data’ and ‘next’.’data’ is the data of the nodes and ‘next’ stores
the address of the next node.
Less memory is required for storing the members (2 members – data and next)
Insertion and Deletion don’t require the shifting of all elements as required in the array
Sample output:
********************************** [ MAIN MENU ] ***********************************
3.Search for a passenger using the passport number and return the record of him.
*************************************************************************************
---------------------------------------------------------------------
Flight#: Capacity Reserved# Departure date Arrival date Departure city Arrival city
*************************************************************************************************
---------------------------------------------------------------------
Flight#: Capacity Reserved# Departure date Arrival date Departure city Arrival city
*************************************************************************************************
---------------------------------------------------------------------
3.Search for a passenger using the passport number and return the record of him.
*************************************************************************************
Flight#: Capacity Reserved# Departure date Arrival date Departure city Arrival city
*************************************************************************************************
Confirmation list
~-~-~-~-~-~-~-~-~
3.Search for a passenger using the passport number and return the record of him.
*************************************************************************************
Flight#: Capacity Reserved# Departure date Arrival date Departure city Arrival city
*************************************************************************************************
3.Search for a passenger using the passport number and return the record of him.
*************************************************************************************
---------------------------------------------------------------------
Flight#: Capacity Reserved# Departure date Arrival date Departure city Arrival city
*************************************************************************************************
---------------------------------------------------------------------
Flight#: Capacity Reserved# Departure date Arrival date Departure city Arrival city
*************************************************************************************************
---------------------------------------------------------------------
3.Search for a passenger using the passport number and return the record of him.
*************************************************************************************
Flight#: Capacity Reserved# Departure date Arrival date Departure city Arrival city
*************************************************************************************************
3.Search for a passenger using the passport number and return the record of him.
*************************************************************************************
The code:
def get_passport_number(self):
return self.__p_number
def get_passenger_name(self):
return self.__p_name
def get_next(self):
return self.__next
# to check if the list is empty or not true if it is empty otherwise return false if
not empty
# O(1)
def isEmpty(self):
return self.head is None
else:
n = self.head # otherwise, move to the end of the list
while n.get_next():
n = n.get_next()
n.set_next(Node(p_number, p_name, cost)) # add to the last of the list
# O(1)
def get_next(self):
return self.__next
# O(1)
def set_next(self, nxt):
self.__next = nxt
# O(1)
def get_flight_number(self):
return self.__flight_number
else:
print(f"No passenger with passport number {p_number}")
print("**********************************************************************************
***************")
def isEmpty(self):
return self.head is None
def size(self):
count = 0
n = self.head
while n:
n = n.get_next()
count += 1
return count
def print_all(self):
if self.head is not None:
self.head.headers()
n = self.head
while n:
n.flights_information_main() # call flights_information_main from flight
class
n = n.get_next()
print()
while line != '': # read to the end of the file line by line
ls = line.split(',')
flight_obj = Flight(ls[0], int(ls[1]), ls[2], ls[3], ls[4], ls[5]) # declare an
object from the flight
air_line.insert(flight_obj) # insert new flight into the ssl_flights
line = input_file.readline() # read next line
input_file.close() # close file after finish
if ch == 1:
flight_number = input("Enter flight number: ")
capacity = int(input("Enter capacity of the flight: "))
departure_date = input("Enter departure date: ")
arrival_date = input("Enter arrival date: ")
departure_city = input("Enter departure city: ")
arrival_city = input("Enter arrival city: ")
anEntry = Flight(flight_number, capacity, departure_date, arrival_date,
departure_city, arrival_city)
air_line.insert(anEntry)
elif ch == 2:
air_line.print_all()
f_num = input("Enter Flight number: ")
if air_line.search(f_num):
p_num = int(input("Enter passport number: "))
p_name = input("Enter passenger name: ")
cost = float(input("Enter cost of the flight: "))
air_line.add_passenger(f_num, p_num, p_name, cost)
print("New passenger is added successful")
elif ch == 3:
break
else:
print("invalid choice")
print("**********************************************************************************
***")
choice = int(input("Enter your choice:"))
if choice == 1:
add_new_record_to_the_system()
elif choice == 2:
air_line.print_all()
f_number = input("Enter Flight number: ")
if air_line.search(f_number):
p_number = int(input("Enter passport number: "))
air_line.reservation_cancel(f_number, p_number)
else:
print("Invalid flight number")
elif choice == 3:
air_line.print_all()
f_number = input("Enter Flight number: ")
if air_line.search(f_number):
flight = air_line.get_flight(f_number)
passport_number = int(input("Enter passport number: "))
flight.search_by_passport_number(p_number)
else:
print("Invalid flight number")
elif choice == 4:
p_number = int(input("Enter passport number: "))
air_line.search_by_passport_number_in_all_flights(p_number)
elif choice == 5:
air_line.print_all()
f_number = input("Enter Flight number: ")
if air_line.search(f_number):
air_line.print_flight_by_number(f_number, 2) # key: (1. c&w || 2.C only ||
3.W only)
else:
print("Invalid flight number")
elif choice == 6:
air_line.print_all()
f_number = input("Enter Flight number: ")
if air_line.search(f_number):
air_line.print_flight_by_number(f_number, 3)
else:
print("Invalid flight number")
elif choice == 7:
print("Thank you for using flight reservation system")
break
else:
print("Invalid menu choice")