## 3. An array of size n consists of records where the record consists of numbers consisting of three digits from 900 to 999 ## . Delete m numbers at given positions. All the occurrences of that number are to be deleted.Also print the size of the ## array and the array itself at the end of the program. from time import clock import sys ## Start def delete_array(array_list,delete_list): memory=0 shift=0 array_length=len(array_list) delete_length=len(delete_list) no_of_num_delete=0 for i in range(0,delete_length): for j in range(0,array_length): if array_list[j]==delete_list[i] : no_of_num_delete+=1 for k in range(j,array_length-1): array_list[k] = array_list[k+1] shift+=1 del(array_list[array_length-no_of_num_delete-1:array_length-1]) memory=memory+sys.getsizeof(array_list)+sys.getsizeof(array_length)+sys.getsizeof(delete_length)+sys.getsizeof(no_of_num_delete) return array_list,memory,shift ## End InFile_Input=open("in8_3.txt","r") InFile_Del=open("in8_3_del.txt","r") Input=[] Delete=[] for row in InFile_Input: temp=row.split(",") for i in temp: Input.append((i)) InFile_Input.close() for row1 in InFile_Del: temp1=row1.split(",") for j in temp1: Delete.append((j)) InFile_Del.close() start=clock() Modified_Array,Memory_Used,No_of_Shifts=delete_array(Input,Delete) time_taken=clock()-start OutFile=open("out_3_8_3.txt","w") OutFile=open("out_3_8_3.txt","a") OutFile.write("\n Modified Array After deletion is as Follows \n") for a in Modified_Array: if a == Modified_Array[len(Modified_Array)-1]: OutFile.write(a) else: OutFile.write(a + ',') OutFile.write("\n\n\n\n New Size Of Array = " + str(len(Modified_Array)) ) OutFile.write("\n Time Taken = " + str(time_taken) + " seconds. \n") OutFile.write(" Memory Used = " + str(Memory_Used) + " bytes. ") OutFile.close() print "Output File Is Generated"