Wednesday, 4 June 2025

GRADE 12 PRACTICAL 13

'''A stack named StuStack contains records of students.Each record is represented as a list,eg [101, 'Ravi', 87.5]

Write the following user-defined functions :

(i) pushStu(StuStack,StuList):

this takes StuStack and a list of students as arguments, and pushes the list into the stack.

(ii) popStu(StuStack):

This function pops the topmost student record from the stack and returns it. If empty, display the message

"Stack Underflow" and return None.

(iii) display(StuStack):

This function should display the student by popping it one by one. Also display the record with the highest marks. If the stack is empty, display "No student records".

'''


StuStack=[]


def menu():

    while True:

        ch=int(input("""MENU :

1.PUSH

2.POP

3.DISPLAY

4.EXIT"""))

        if ch==1:

            StuList=[]

            n=int(input("Enter no of records you want to add : "))

            for i in range(n):

                stuid=int(input('Enter student id : '))

                name=input("Enter name : ")

                marks=float(input('Enter marks : '))

                l=[stuid,name,marks]

                StuList.append(l)

            pushStu(StuStack,StuList)

        elif ch==2:

            rec=popStu(StuStack)

            if rec:

                print(rec)

            else:

                print('Empty')

        elif ch==3:

            display(StuStack)

        else:

            break


def pushStu(StuStack,StuList):

    for i in StuList:

        StuStack.append(i)


def popStu(StuStack):

    if len(StuStack)>0:

        return StuStack.pop()

    else:

        print('STACK UNDERFLOW')

        return None

    

def display(StuStack):

    maxx=0

    if len(StuStack)==0:

        print('Empty Stack')

        return

    while StuStack:

        rec = StuStack.pop()

        print(rec)

        if rec[2]>maxx:

            maxx=rec[2]

            Student=rec

        

    print('Student with maximum marks : ',Student)


menu()