Skip to main content

STACK ASSIGNMENT | 24TH OCT

 

STACK ASSIGNMENT

QUE 1:

[1] A ____________ is a way to store, organize, or manage data in efficient and productive manner.

[2] A stack is one of the following types of data structure?

a) Linear b) Dynamic c) Circular d) All of these

[3] Stack data structure is following ____________ principle.

[4] In stack data can be inserted or deleted from ____________ only.

[5] The insert operation in the stack is known as pop. (True/False)

[6] You can replace any element position in the stack. (True/False)

[7] The peek operation refers to accessing/inspecting the top element in the stack. (True/False)

[8] A condition raise due to the stack is full is known as ___________.

a) Underflow b) Overflow c) List is full d) Completely Filled

[9] While popping the element from the stack, a condition will be raised, this condition is known as ____________.

a) Underflow b) Overflow c) List is Empty d) Blank List

[10] Stack overflow condition is raised in ____________ operation where as Stack underflow condition is raised in _____________ operations.

Push, Pop

QUE 2:

1.     1. What do you mean by data structure? Explain your answer with a suitable example.

2.     2. Write a function to display the stack elements.

3.     3. Write a python function named is_underflow() to check a stack is an underflow.

4.     4. Write functions AddPlayer(player) and DeletePlayer(player) in python to add and remove a player by considering them as push and pop operations in a stack.

        ______________________________________________________________________________

5. Write a function in Python, Push (Vehicle) where, Vehicle is dictionary containing details of vehicles –

{Car_Name: Maker}. The function should push the name of car manufactured by 'TATA' (including all the possible cases like Tata, TaTa, etc.) to the stack.

For example: If the dictionary contains the following data:

Vehicle={"Santro": "Hyundai", "Nexon": "TATA","Safari": "Tata"}

The stack should contain -

Safari

Nexon

Pop() – pops and displays the topmost element of the stack, if the stack is not empty.

Sol:

stack = []

def Push(Vehicle):

    for v_name in Vehicle:

        if Vehicle[v_name].upper() == "TATA":

            stack.append(v_name)

    # Display stack after pushing

    for car in stack:

        print(car)


def Pop():

    if stack == []:

        print("Stack is empty, nothing to pop!")

    else:

        item = stack.pop()

        print("Popped item:", item)

        print("Stack after Pop:", stack)


#  dictionary

Vehicle = {"Santro": "Hyundai", "Nexon": "TATA", "Safari": "Tata"}


# function call

Push(Vehicle)

Pop()


 6. A list contains following record of customer : [Customer_name, Room Type]

Write the following user defined functions to perform given operations on the stack named 'Hotel':

(i) Push_Cust() - To Push customers' names of those customers who are staying in 'Delux' Room Type.

(ii) Pop_Cust() - To Pop the names of customers from the stack and display them. Also, display "Underflow" when there are no customers in the stack.

For example:

If the lists with customer details are as follows:

["Siddarth", "Delux"]

["Rahul", "Standard"]

Sol:

Hotel = []

Customer = [["Siddarth", "Delux"], ["Rahul", "Standard"], ["Jerry", "Delux"]]

 

def Push_Cust():

    for rec in Customer:

        if rec[1].upper() == "DELUX":

            Hotel.append(rec[0])

    print("Stack after Push:", Hotel)

 

def Pop_Cust():

    if len(Hotel) > 0:

        while len(Hotel) > 0:

            print("Popped:", Hotel.pop())

    else:

        print("Underflow")

 

# Function calls

Push_Cust()

Pop_Cust()



W



5. 

5

Comments

Popular posts from this blog

GRADE XII - Python Connectivity with MySQL

  Python Connectivity with MySQL In real-life applications, the data inputted by the user and processed by the application needs to be saved permanently, so that it can be used for future manipulation. Usually, input and output data is displayed during execution but not stored, as it resides in main memory , which is temporary — i.e., it gets erased once the application is closed. This limitation can be overcome by sending the data to be stored in a database , which is made accessible to the user through a Front-End interface . Key Concepts Database A database is an organized collection of data that is stored and accessed electronically from a computer system. DBMS (Database Management System) A DBMS is software that interacts with end-users, applications, and the database to capture and analyze data. Front-End The Front-End is the user interface of the application, responsible for input/output interaction with the user. Back-End The Back-End refe...

GRADE XII - CSV FILE

CSV FILE (COMMA SEPERATED VALUE) CSV NOTES LINK :  CSV NOTES - CLICK HERE Writing data to a CSV file involves the following steps: Import the csv module Open the CSV file in write mode ( "w" ) using open() Create the writer object Write the data into the file using the writer object Close the file using close() writerow() Method This method is used to write a single row to a CSV file. It takes a sequence (list or tuple) as its parameter, and writes the items as a comma-separated line in the file. You do not need to add a newline character (\n) — it automatically places the end-of-line marker.     EXAMPLE 1: import csv  # Importing the csv module # CSV file opened using relative path csv_fobj = open("emp.csv", "w")   # Writer object created wtr_obj = csv.writer(csv_fobj) # Record with field heading is written wtr_obj.writerow(["Empno", "Name", "Salary"]) # Records with data are...