Skip to content

Instantly share code, notes, and snippets.

@h26k2
Created July 7, 2020 13:52
Show Gist options
  • Save h26k2/c389f55c14589adc53bec2f7089ffbe4 to your computer and use it in GitHub Desktop.
Save h26k2/c389f55c14589adc53bec2f7089ffbe4 to your computer and use it in GitHub Desktop.
3rd semester data structure mid programs python guide
option = int(input("What you want to run \n1) insert a record \n2) remove a record \n3) check for array is underflow or overflow \n4) search a record \n5) sort records \nPlease choose any one option : "))
def insertRecord():
records = []
noOfRecords = int(input("How many numbers you want to insert ? "))
for x in range(noOfRecords):
tempRecord = int(input("Enter record " + str(x+1) + " : "))
records.append(tempRecord)
print("You've successfully inserted records to the array !")
print("********************************")
print("R E C O R D S ")
print("********************************")
print(records)
def removeRecord():
records = [10,9,8,262,6,78]
print(records)
recordToRemove = int(input("Enter the record you want to delete from the above metioned arrray : "))
if recordToRemove in records:
records.remove(recordToRemove)
print("[Record successfully removed!]")
print("****************************")
print("Results")
print("****************************")
print(records)
else:
print("[The record which you've inputted is already not existed in the array]")
def searchRecords():
# populating array
records = []
for x in range(100):
if (x+1)%2 == 0:
records.append(x)
print(records)
toSearch = int(input("Enter a record you want to search : "))
foundStatus = False
foundIndex = None
for x in range(len(records)):
if records[x] == toSearch:
foundIndex = x
foundStatus = True
break
if foundStatus == True:
print("Successfully found record : " + str(records[foundIndex]))
print("Your inputted record is stored in index : " + str(foundIndex))
elif foundStatus == False:
print("Sorry your inputted number is not found !")
def sortRecords():
# populating array
records = []
for x in range(50):
if (x+1)%2 != 0:
records.append(x)
for x in range(50,0,-1):
if (x+1)%2 == 0:
records.append(x)
print("Records in The array")
print(records)
sortStyle = int(input("Enter the sort style you want to sort the records above \n1) ascending order sort \n2) descending order \nChoose any one : "))
if sortStyle == 1:
records.sort()
print("\n\nSuccessfully sorted records in ascesnding order")
print("***********************************************")
print("RESULTS")
print("***********************************************")
print(records)
elif sortStyle == 2:
records.sort(reverse = True)
print("\n\nSuccessfully sorted records in ascesnding order")
print("***********************************************")
print("RESULTS")
print("***********************************************")
print(records)
else:
print("Please choose 1 or 2")
def arrayCheck():
size = int(input("Enter the size of the array you want to declare : "))
records = [None] * size
recordCount = int(input("Enter the no of records you want to store in the array : "))
check = None
if(recordCount <= size):
check = "underflow"
else:
check = "overflow"
for x in range(recordCount):
if x > size-1:
print("*******************************")
print("==> A R R A Y I S O V E R F L O W <==")
print("New records are skipped")
print("*******************************")
print("*******************************")
print("Records in the array")
print(records)
print("*******************************")
break
tempR = int(input("Enter record " + str(x+1) + " to enter : "))
records[x] = tempR
if check == "underflow":
print("==> A R R A Y I S U N D E R F L O W <==")
print(records)
if option > 0 and option <= 5:
if option == 1:
insertRecord()
elif option == 2:
removeRecord()
elif option == 3:
arrayCheck()
elif option == 4:
searchRecords()
elif option == 5:
sortRecords()
else:
print("Please choose a option between 1 to 5")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment