0% found this document useful (0 votes)
45 views10 pages

Data Structure

Class 12 complete science data structure chapter notes and pyq with solution

Uploaded by

manjeet.kvs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
45 views10 pages

Data Structure

Class 12 complete science data structure chapter notes and pyq with solution

Uploaded by

manjeet.kvs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
Key Points > Data Structures : It represents how data is stored / organized in Computer's Memory . A data structure defines a mechanism to store, organise and access data along with operations (processing) that can be efficiently performed on the data. > Implementation of Data Structures can_be done in two wavs, Simple Data Structures : Built from primitive data types (integers, real, charater, Boolean) Example: Arrays or Linear List Compound Data Structures: Simple Data structures are used to form more complex data structure. They are classified into two types Linear : means elements are stored in sequential order Example: Stack, Queue, Linked List Non Linear : Data can be stored as multilevel Structure, Example Trees , Graphs > STACK * Stack is a Linear Data Structure. * Stack is a list of elements in which an element may be inserted or deleted only at one end, called the TOP of the stack * It follows the principle Last In First Out (LIFO). LIFO means the element inserted last would be the first to be deleted. Operations on Stack: There are mainly Two types of Operations that can be done with Stack. Push: Insertion of an element on top of the stack is called Push. Pop: Removal an element from the top of the stack is called POP. Push and Pop Operations are done from single end called TOP > Overflow : It refers to a situation, when one tries to push an element in stack / queue, that is full. In Python, (for stacks and list implemented as list), since list can grow, OVERFLOW condition does not arise until all memory is exhausted. ‘Question Bank — Class XII (Computer Science) By: Swati Chawla > nderflow strefers to situation when o tes jelte an tem from an empry qa what istck of gueue i cure Atm and sil oe et Pop an it priven Program to i Mons Poperations Using Ligy mt sth): Ct eg i # Or if len(st return True else: return False det Push(stkelt) stkappend(elt) print("Element inserted, def Pop(stk): ifisEmpty(sth): print(*Stack Empty Underiow Case else: ‘prini(‘Deleted Element is def Peek(sth): ifisempty(stk): print("Stack is Empty...) else: print("Element at Top of the Stack * tht) det Display(stk): ifisEmpty(stk): print("Stack Empty. else: for’ in range(len(stk)-1,-1,-1}; print(stk{i]) “stk. pop()) -STACK OPERATIONS....") 1. PUSH’) 2. POP") 3. PEEK") print(” 4. DISPLAY") print’ 5. EXIT") ch=int(input("Enter your choice :*)) ifch==1; element=int(input("Enter the element Which you want to push :" )) 1 4 6. Push(Stack itch==2: element) Pop(Stack) ifch==3: Peek(Stack) if ch==4: Display(Stack) elif ch==5: break Scan this QR Code For Video Explanation of Data Structures Objective Type Questions Data structure Stack is based on property. (a) First in First Out (®) First in Last Out (© Last in First Out @)_—_Lastin Last Out In Stack, all operation takes place at, (@) Top v (b) Front © — Rear @ Any Insertion and Deletion operations of Stack are known as respectively. (@) Insertion and Deletion (b) Push and Pop ¥ (© Popand Push (@) —_Enqueue and Dequeue When a stack is full and an element's is tried from it, it is called a case, ser (@) —_Underflow (b) Overflow ¥ (© Extraflow @ —_Noflow When a stack is empty and an element's deletion is tried from the stack, it is called a Bssrevsas CRBCH (a) Underflow ¥ (b) Overflow (© Extraflow @ —Noflow Which of the following is an application of stack? Question Bank — Class Xl (Computer Science) By: Swati Chawla (@) Finding the factorial of a number (6) Reversing of a string (© Infix to postfix (a) Allof these V If the elements ‘A , ‘BY , °C’ and ‘D? are placed ina Queue and are deleted one at a time, in what order they will be removed? @ ABCD ¥ ) — DCBA (©) DCAB @) ABDC Consider the following code: push(S) push(8) op Push(2) push(5) pop pop op Push(1) op ‘The output of the above code snippet is: (@) 85251 v () 85521 © 82551 @ 81255 9. Consider the following stack of characters implemented as an_ array of 4 elements: STACK =[ ‘A’, ‘J’, ‘P?,‘N?] Describe the stack as the following operations take place. (@) STACK. pop () [a’,3,'P') PO (b) — STACK.append (‘K°) CAW,PYR] (©) STACK. append (‘S*) KS] @ pop () [A\J\P!'K'] POP='s' (© STACK. append (‘G*) CANT,PKYG] Practice Questions (Solved) 1, Find the output of the following code: (@) result numberList = [10,20,30] numberList.append(40) result = result + numberList.popQ, result = result + numberList.popQ) print(“Result =”, result) ‘Ans, Result =70 (b) answer =] ; output =" —_— ch = answer. ‘output = output +h ‘ch = answer-popO output = output + eh print(Result=", output) Ang, Result = MAT 2. What is a Data-Structure ? Ans A. data-structure is logical W8Y a organizing data in memory that consis tly the items stored but also the relation famong items, so as to give efficient and oP performance. In other words, itis 4 Wa) & organizing data such that it can be US efficiently, 3. Write the operations possible in ! structure, A ‘Ans, ‘The major operations are Traverst' Insertion, Deletion, Searching 4. Define stack. AA stack is a data structure that allows adding and removing elements in a particular order. Every time an element is added, it goes on the top ofthe stack; the only element that can be removed s the ‘element that was atthe top of the stack. the data 5. Differentiate between Push and Pop operations in the context of stacks. ‘Examination, 2022 ‘Ans. 1. PUSH: The addition of elements is known as PUSH operation. It is done using the TOP position. 2. POP: Removal of elements is known as POP ‘operation. It is also done using the TOP positon. 6. Give any two characteristics of stacks. Ans. Characteristics of Stacks: (@) [visa LIFO data structure. (b) The insertion and deletion happens at one end is. from the top of the stack. 7. What is a stack? What basic operations can be performed on them? ‘Ans. A stack is a basic data -structure where insertion and deletion of data takes place at one end called the top of the stack, i. it follows the Last In-First Out(LIFO) principle. In Python, a stack is generally implemented as lists. ‘Operations performed on Stack (a) Push ie, Insertion of element in the stack. (b) Pop i-e., Deletion of an element from the stack. (c) Peek i.e, viewing topmost element without removing it. ‘Question Bank ~ Class Xil (Computer Science) By: Swati Chawla 4 or view all the elements in the c east some applications of ick, Stag peeause of LIFO property of stucky, ya bechin various applications like uence, : cee tn emerson, + ean pret EXPRESSION evalu ‘many more on, 9, What is Overflow case? . trees 0 Sitation, When oy, fo pushan element in stack / queue, thatig iy cl stacks ard list implemented ly a at can gt0%%, OVERFLOW condign fot aise until all memory is exhausted, sy is Underflow case? Pmbopadelete an item from an empry stl Wgue That isstack oF queue is curently gt avetem and sill one eS 0 pop anit, 1 teeStack sa linear data structure whi follows a particular order in which the Aperatons are performed” What i the Te vnich the operations are performed iq, Stack ? Name the List method/function Sefitable in Python which is used t0 remy, ihe last element from a list implementeg, stack, Also write an example using Pythoy Statements for removing the last element of thelist. BSE Examination, aap ‘Ans "Onder of operations performed in a Stagkiy LIFO (Last In First Out) + The List method in Python to remove the last element from a list implemented stacks + Example: L=[10,20,30,40] L-pop() OR L.pop(-1) 12. Write PushOn(Book) and Pop(Book) methods / functions in Python to add a new book and delete a book from a List of Book titles, considering them to act as push and pop ‘operations of the Stack data structure, ty def PushOn(Book): aint(input("Enter package title :")) Book. append(a) def PopBook(Book): if (Book ==) print( "Underflow Case. else: print ("Deleted element:", Book.pop()) 13. Write a function —_in__ python MakePush(Package) and MakePop (64) -- (Package) to add a new p, Package from a List ot mae and delete a considering them to operations of the Stack data st def MakePush(Package). a ‘int(input(“Enter ” Package.append(ay sate: +) def MakePop(Package): if (Package==[}); Print( "Underflow Case, else: Print ("Deleted eleme, Package.pop()) 14. Julie has created a dictio, names and marks as key students, Write a program, with 5 functions to perform th operations: @ Push the keys (name of the stude, dictionary into a stack, wiles path corresponding value (marks) © Pop and display the conte, For example: dictionary is as follows: R={"OM":76, "JAI": "ALI":65, "ANU":90, ‘The output from the program should be: TOM ANU BOB OM” “Houle be: nary containing value pairs of 6 eparate user defi following ) is 75 oF more, ‘nt of the stack, If the sample content of the ee CBSE Sample Paper (2021-22) R={"0M":76, "JAI":45, "BOB":89," ALI":65, "ANU":90, "TOM":82} def PUSH(S,N): S.append(N) def POP(S): ifs!=[); return S.pop) else: return None sT=[] fork in R: if R[k}>=75 PUSH(ST,k) while True if ST!=[] print(POP(ST),en¢: else’ break 15. Alam has a list containing 10 integers. You need to help him ereate a program with separate user defined functions to perform Question Bank ~ Class Xi! (Computer Science) By: Swati Chawla the following operations based on this list. © Traverse the content of the list and push the even numbers into a stack. * Pop and display the content of the stack. For Example: If the sample Content of the list Is as follows: N=[12, 13, 34, 6, 21, 79, 98, 22, 35, 38] Sample Output of the code should be: 38 22.98 56 34 12 Ans.N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38] def PushiSt): Stappend() ef Pop( St): ifsti=p): return St.pop() else: return None set) fori in: itix2—o: PushiSti) while True ifSti=f): print(Pop(St),end=!') else: break 16. Alam has a list arr containing 10 integers. You need to help him create a program with a separate user defined function | Push Q. Create a stack and Push those elements from | . list arr, which are at even position. Exg. arr = [20,30,40,50,60,70] ‘The sample output will be : [20,40,60] Ans. Arr=[20, 30, 40, 50, 60,70] Stack=[] def Push () : for iin range(len(Arr)) if % 2—=0: Stack append(Arr{iJ) print(Stack) 17. Write function in Python PUSH(Ar®), where Arr is alist of numbers. From this list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at least one element, otherwise display appropriate error message. ‘CBSE Sample Paper (2020-21) Ans. def PUSH(Arrvalue): sll for x in range(0,len(Art)): if Arr[x]%S=0: (85) ; sappend(ArtsD) len(s)==0: print"Empty Sek’) else: print(s) 18. Write a function in Python PO Arr is a stack implemented ©) numbers. The function returns. Me. Sig deleted from the stack. Compartmne .21) ‘case Sample Parer ( Ans. def popStack(st): # If stack is empty ifllen(st)=0: print("Underflow") else: L=len(st) valest{L-1] print(val) stpopt-) 19, BCCT has created a dictionary containing 10? yyers and their runs as key value pairs 0 Cricket team, Write a program, with separate user defined functions to perform the following operations: « Pash the keys (name ofthe players) ofthe dictionary into a stack, where the corresponding value (runs) is greater than 49. ‘© Pop and display the content of the stack. For examph i If the sample content of the dictionary is follows: SCORE: "SAURAV":80, "RAHUL" "YUVRAJ":110, } ‘The output from the program should be: YUVRAJ SAURAV SACHIN "SACHIN":S5, 5, "YUVRAS":110} "KAPIL":40, "SACHIN":55, 5S, def PUSH(S,R): S.append(R) def POP(S): if SI=[) retum S.pop() else: retum None #Message st] for k in SCORE: if SCORE[K]>49: PUSH(ST,{) while True: ‘Question Bank ~ Class XII (Computer Science) By: Swati Chawla else: break has alist containing 10 studen es venneed ‘to help him create a pro, = May «You nesieer defined functions to pent” Mi owing operations based on this inv yaverse the content ofthe list ang savers higher than 33 info a stack, "th, Iumop and display the content Of th yyy For Example: 4 ne sample Content of tHe List agg, a 12, 13, 34, 56, 21, 79, 98, 22, 35, 2m Semple Output of the code should be; 38 35.9879 56 34 sepa the foll BSE Sample Paper NE{12, 13, 34, 56,21, 79, 98, 22, 35, 39) def PUSH(S.N): S.append(N) def POP(S): if S!-( return S.pop() else: return None st-) for k in N: if k>33: PUSH(ST.¥) while True: if ST!=[): print(POP(ST),end=" else: break 21. Raghay has created a vocabulary list. You need to help him create a program with separate user defined functions to perform the following operations based on this list, @ Traverse the content of the list and push the entries having less than 7 characters into a stack. ¢ Pop and display the content of the stack, For Example: Ifthe sample Content of the lst is as fllons; W=[‘Elucidate’, ‘Haughty’, ‘Pacify’, ‘Quip’, ‘Rapport’, ‘Urbane’, ‘Young’,‘Zenith’] ‘Sample Output of the code should be: ‘Zenith Young Urbane Quip Pacify Ans. Ans. Blucidate''Haughty’Pacify''Quip', "Rapport, Urbane’ , 'Young’,' Zenith’] def PUSH(S,W): S.append(W) def POPS): (86) if SI=Q: return S,pop() else: ‘The output from the program should be: return None nga China Tada ist=| ots ae R= ("UK":"Europe" , "India":"Asia", if len(i}<7: "China’:"Asia" ,"Egypt’:"Africa", "Cuba": PUSH(WList,i) rarer aap "Asia"} while True: eee ree def Pop(Stack): pe ORL aces if Stack!=[): else: or ie Stack pop) 22. Vishal has created a List Arr retum None clements. Help him to create Sac Stack={] Penetjogs 0 [perform the\tunowing mace Se ae Create a Stack after checking the ieee: HERDS Asi itis even muldply it by 2, and ifthe element Push(Stack,i) odd, then“ multiply ig Panes wala cs ; Pop and display the contents ofthe strc, ° ise een Ans. 0 en at=(2,3,4,5,6,7,8,9,10] a PB Stack=[] re def Push(elt) 24, Write a function POP( ) which removes Stack.append(elt) values from stack named “MyStack”. . def Pop(Stack): def POP (MyStack) if Stack!=[) iflen (MyStack ) > 0 return Stack.pop() MyStack.pop() 2 ee tim2— 0: print Stack s Empty now.” Push(i*2) 25, Write separate user defined functions for the tees following : Push(i*3) (i) PUSH(N) - This function accepts a list of hile Tru names, N as parameter. It then pushes only | wif Stack!=(] those names in the stack named OnlyA which < the letter ‘A’, ene poe CRBS Examination, 2022 Caak (ii) POPA(OnlyA) - This function pops each name from the stack OnlyA and displays it. 23. Rockey has created a dictionary containing When the stack is empty, the message "EMPTY" is displayed. For example : If the names in the list N are ('ANKITA', ‘NITISH', ‘ANWAR’, ‘DIMPLE’, 'HARKIRAT’] countries and continent as a key value pair of 6 countries, Write a program with sepa | user — defined functions to perform the following operations: Push the keys (name of the country) of the dictionary into a stack , where country Then the stack OnlyA should store belongs to continent “Asia”. ('ANKITA’, ‘ANWAR, 'HARKIRAT’] Pop and Display the content of the stack. ‘And the output should be displayed as For Example, HARKIRAT ANWAR ANKITA EMPTY If the sample content of the dictionary is as eneesne pallens: for aName in N R= {“UK”:”Europe” , “India”:"Asia”, tAtweNans “China”:" Asia” , “Egypt”:"Afriea", “Cuba” : OnlyA.append(aName) “America” , “Japan”: “Asia”) def POPA(OnlyA): Question Bank ~ Class Xi (Computer Science) (87) By: Swati Chawla “— while Onlya : print(OnlyA.popO, end="") else : print(EMPTY") OnlyA=f] - Names=[ANKITAY, 'NITISH, ‘ANWAR’, ‘DIMPLE’, HARKIRAT] PUSH(Names) POPA(OnlyA) c 26. Write the following user defined ae (@ pushEven() - This function accepts * of integers named N as parameter. It then pushes only even numbers into the stack named EVEN. (i) popEven(EVEN) - This function pops each integer from the stack EVEN and displays the popped value. P Whten the stack fe empty, the message "Stack Empty" is displayed. For example: Ifthe list N contains = 110,5,3.8,15,4] ‘Then the stack, EVEN should store [10,841 And the output should be 4 8 10 Stack Empty Compartment Examination, 2022 Ans. def pushEven(N): for z in N if2%2—0 EVEN.append(z) def popEven(EVEN): while EVEN print(EVEN.pop(), end else print(‘Stack Empty’) EVEN={] N=[10,5,3,8,15,4] pushEven(N) popEven(EVEN) 27. Write the definition of a user defined function PushNV(N) which accepts alist of strings in the parameter N and pushes all strings which have no vowels present in it, into a list named NoVowel. Write a program in Python to input Words and push them one by one into a list named All. ‘The program should then use the function PushNV() to create a stack of words in the list NoVowel so that it stores only those words which do not have any vowel present in it, from the list All. ‘Thereafter, pop each word from the list NoVowel and display the popped word. When the stack is empty, display the message Question Bank - Class Xil (Computer Science) By: Swati Chawla (88) wpmptyStacl ample For Words accePted ANd pusheq if inty th ANRY', LIKE’ RHYTHM, Wop fe stack NoVowel should They, RHYTHM’, 'GYM'] 3 ‘he output should be displayeg [YTHM DRY EmptyStacy CBSE Exam tore And GYM RH ns. at pushNV(N): for Win N: for Cin We if Cupper() in 'AEIOU': break Ise: ee oVowel.append(W) Novovel-O ioVowel-| wet rangetS): “All appendinput(Enter a Word: ‘)) PushNV(AI) while NoVowel print(NoVowel.pop0), end: else: print(‘EmptyStack’) 28, Write the definition of a user definey function Push3_5(N) which accepts a list of integers in a parameter N and pushes all those integers which are divisible by 3 or divisible hy 5 from the list N into a list named Only3, ‘¢ Write a program in Python to input 5 integer into alist named NUM. The program should tg use the function Push3_5() to create the stack of the list Only3_5. Thereafter pop each integer from the list Only3_5 and display the popped value. When the list is empty, display the message "StackEmpty". For example: If the integers input into the list NUM are; {10,6,14,18,30] ‘Then the stack Only3_5 should store {10,6,18,30] ‘And the output should be displayed as 30 18 6 10 StackEmpty Ans. CBSE Examination, 202 def Push3_S(N): foriinN: if1%3=0 oF i%5—0 Only3_5.append(i) NUM=[] ') ly3_ 50 fpriinrange(S): NUM.append(int(input(‘E; push3_S(NUM) ‘let an Integer: 9) while Only3_5 : print(Only3_S.pop(, en ase: print('StackEmpty’) 29. Write the definition of a fu POP_PUSH(LPop, LPush, mine a function should Pop out the last Nene THE thelist LPop and Push them inte yee" of LPush. Cor a For example: If the contents of nee et are [10, 18,20, 30] And value of \ pence? then the funeton should create heat Pag as [30, And the list L) tontain [10,15] men teeter . NOTE: If the value of N is number of elements presen display the message “ Ans. def POP_PUSH(LPop, LPush, N): if Ne“len(LPop): for iin range(N): p=LPop.pop() | ‘LPush.append(p) ‘More than the PB t in LPop, then Pop not possible”, #LPush.append(LPop.pop()) else: print("Pop Not possible..") print(LPush) print(LPop) LPop=[10, 15, 20, 30] Ne LPush={] POP_PUSH(LPop,LPush,N) 30. Write functions in Python for PushS(List) and for PopS(List) for performing Push and Pop operations with a stack of List containing integers. ‘Compartment, 2020 Ans. def PushS (List): Neint(input(“Enter integer:”)) List.append(N) def PopS(List): if (List print( else: print("Deleted Integer:" List.pop()) 31. Consider a list named Nums which contains random integers. ): tack Empty") 89 Question Bank - Class Xil (Computer Science) (891 By: Swati Chawla ‘Write the following user defined functions in Python and perform the specified operations ona stack named BigNums. (®) PushBigQ: It checks every number from the list Nums and pushes all such numbers Which have 5 or more digits into the stack, BigNums. Ci) PopBig0: It pops the numbers from the Stack, BigNums and displays them. The function should also display "Stack Empty” When there are no more numbers left in the stack, For example: If the list Nums contains the following data: Nums = [213, 10025, 167, 254923, 14, 1297653, 31498, 386, 92765] ‘Then on execution of PushBig(), the stack BigNums should store: 110025, 254923, 1297653, 31498, 92765] And on execution of PopBig(), the following output should be display. 92765 31498 1297653 254923 10025 Stack Empty CBSE Examination, 2024 Ans, def PushBig(Nums,BigNums): for N in Nums: if len(str(N)) >= 5: BigNums.append(N) def PopBig(BigNums): while BigNums Print(BigNums.pop()) else: print("Stack Empty") OR def PushBig() for N in Nums: ifN >= 10000: BigNums.append(N) def PopBig0): while BigNums: print(BigNums.pop()) print("Stack Empty") 32. A list contains following record of customer: (CBSE Examination 2023 [Customer_name, Room Type] ‘Write the following user defined functions to perform given operations on the stack named "Hotel" Push_Cust()- To Posh customers’ Mani, Mt Reece eee ‘who are staying in ‘Delus Room Type. i) Pop_Cust() - To Pop customers from the stack Also, display “Underflow” when there ‘customers in the stack. For example : Troe tate wir costomer deta are = 0807? ["Siddarth", "Delux"] ["Rabul", "Standard"] ["erry", "Delux"] The stack should contain Jerry Siddharth ‘The output should be: Jerry Siddharth Underflow Ans, Hotel=[] i Customer=[["Siddarth’, Delux") "Rabu! dard"],{"Jerry","Delux"]] def Push_ Cust): for rec in Customer: ifrec{1 the names of them. and display them. ‘Stan ‘Delux’ Hotel.append(rec{0]) def Pop_Cust() while len(Hotel)>0: print(Hotel.pop0) else: print("Underflow") 33. Write a funetion in Python, Push (Vehicle) where, Vehicle is a dictionary containing details of vehicles — {Car_Name: Maker}. The function should push the name of car manufactured by ‘TATA’ (including all the possible eases like Tata, TaTa, etc.) to the stack, For example: If the dictionary contains the following data : Vehicle={""Santro”:"Hyundai","Nexon":" ATA","Safari":" Tata") ‘The stack should contain Safari Nexon CBSE Examination, 2023 stack=[) def Push(Vehicle) for v_name in Vehicle : if Vehicle{v_name] upper stack.append(y_name) Question Bank — Class XII (Computer Science) By: Swati Chawla 190) EB Uarelea) y (A): Astack is a LIFO = assent) Any Rew cet rata memaack lS gels positioned atthe after the last existing element in the Stay CBSE Examinay 00.24 (A) and (R) are tue and (Ry correct explanation for (A), ) Both (A) and (R) are true and (R the comect explanation for (A). (o (Adis true but () is false (@ (A) is false but (R) is true, ertion (A) # In Python, a stack Jmplemented using 2 list a4 Tegsoning (R): A stack isan ordered jp Reais that works 0 the principle of Fig ut (FIFO). CBSE Compartin {ay Both (A) and (R) are true and (R) ig ‘correct explanation for (A), {by Both (A) and (R) are true and (R) is yy the correct explanation for (A). (6 (A) is true but (R) is false. (a) (A)is false but R) is true. . A list contains following record of course Rea Uaivesiy: CBSE Compartment any {Course_name, Fees, Duration] 23 Waite the following user defined functions to per ven operations on the stack named 'Uniy’ ; (i) Push_element( - To push an object containing jy Course_name, Fees and Duration of a course, whi hhas fees greater than 100000 to the stack i) Pop_element()- To pop the object from the stay and display it. Also, display “Underflow" when they {sno element in the stack For example If the lists of courses details are ["MCA", 200000, 3} ["MBA", 500000, 2) ["BA", 100000, 3] The stack should contain "MBA", 500000, 2} "MCA", 200000, 3) 4. A list, NList contains following record as list elements: CBSE Sample Paper (2023-24) {City, Country, distance from Delhi] Each of these records are nested together to forma nested list. Write the following user defined funetons in Python to perform the specified operations onthe stack named travel. rassertion 1 iS np 2, Ass gp Fin, ’ h_element(NList): jt Ore ‘ the ' or he cs ater) oe te containing nt mportant Poi + whic! ‘ at ance is ess than 3500 kan foe i India ang I Dre sone Pop_elementO: It pops the objet = Ci displays them. Also the func “Suck Empty” when there are ng al display tack. ron example: Ifthe nested list contains the as: following NList=[("New York", "U.S.4.", 117: ['Naypyidaw", "Myanmar", 3219), Dubai’, "UAE", 2194), ["London”, "England”, 6693), [rGangtok", "India", 1580), | [rColumbo, "Sri Lanka", 3405)) 34), ‘The stack should contai [Naypyidaw,, 'Myanmar'), (Dubai, "UAE [Columbo ‘Sri Lanka’) | ‘The output should be: | ‘olumbo’, 'Sri Lanka'} | [Dubai’, "UAE}] [Naypyidaw’, "Myanmar’) Stack Empty Solutions LO 20 3 ‘ourse=[{"MCA",200000,3],{"MBA" Coot [ -500000,2),("B Univ=0) def Push_element() for Rec in Course: if Rec[1]>100000: Univ.append(Rec) def Pop_element() while len(Univ)>0: print(Univ.pop() else: print("Underflow") 4 travel=[] def Push_element(NList: for L in Nlist if L[1]!="India” and L[2}<3500: travel.append((L[0},L[1]}) def Pop_element() while len(travel); print(travel.pop()) else print(“Stack Empty”) Question Bank — Class Xil (Computer Science) By: Swati Chawia a

You might also like