Friday, 15 June 2018

To implement stack using list using python programming.

# To implement stack using list

stackList = []

def nrPush(ele='\0'):
    if ele!='\0':
        stackList.append(ele)
        print("PUSH operation successfully completed.")
    else:
        print("Operation failled.")
        print("Entered element is empty.")

def nrPop():
    if(len(stackList)>0):
        stackList.remove(stackList[-1])
        print("POP operation successfully completed.")
    else:
        print("Operation failled.")
        print("List is empty.")

while(True):
    print("\n\nChoose one option : ")
    print("1. PUSH operation,")
    print("2. POP operation.")
    print("3. Display List element.")
    print("e. Exit")
    op = input()
    if op=='1':
        ele = input("Enter element for PUSH operation.")
        nrPush(ele)
    elif op == '2':
        nrPop()
    elif op == '3':
        if(len(stackList)>0):
            print(stackList)
        else:
            print("List is Empty")
    elif op == 'e':
        break
    else:
        print("Choose correct option.")

6 comments:

  1. experience with this information. We, at the CRS info solutions ,help candidates in acquiring certificates, master interview questions, and prepare brilliant resumes.Find top Salesforce admin interview questions in 2020.
    These Salesforce developer interview questions are highly helpful in 2020. You can read these Salesforce lightning interview questions and Salesforce integration interview questions which are prepared by industry experts.

    ReplyDelete

Featured post

In all other cases the driver is not insured. If the marital status, sex and age of the driver are the inputs, write a program to determine whether the driver is to be insured or not.

  #include #include int main() { char ms;   printf("Is Driver married (Y/N): ");  scanf("%c",&ms);   if(ms=='y&#...

Popular Posts