You are on page 1of 6

AIM: To create a stack using and do some operations like push, pop and display using array.

ALGORITHM: start the program create a structure called stack and its fields are top and items. assign the variables items, I, top, o p, ch . check the index value if it is option 1 is selected push operation is done a) Get the item to be inserted into the stack b) Check the stacksize.if it is full print stack is full otherwise increment the pointer of the stack and push the item into the stack. Step 6: if it is option 2 is selected, pop operation is done a) Check the top of the stack. If the stack pointer point-1 then print Underflow may occur. b) otherwise the top of the stack item is popped and decrement the pointer of the stack. Step 7: if the option 3 is selected , display operation is done a) check the stack ,if it contain item or not b) if not print there is no item in the stack. c) Otherwise retrive the item from the stack. Step 8: if the option 4 is selected , it terminate the execution. Step 9: before we do this operation initiate the top of the stack (ie) the stack Pointer point-1. Step10: stop the execution Step 1: Step 2: Step 3: Step 4: Step 5:

AIM: A Program to create a queue using and do some operations like insert, remove and display using array. ALGORITHM: Step 1: Start the program. Step 2: Create a structure called queue and its fields are front, rear and element. Step 3: Initialize rear to -1 and front to 0 Step 4: Read the option Step 5: If the option is 1then check queue is full or not. If it is not full increment the rear and insert item to that position. If queue is full then display Queue is full. Step 6: if the option is 2 then check the queue is empty or not . if it is not empty . remove the item in front position and increment the front. If queue is Empty . Step 7: if the option 3 then check the queue is empty or not. If it is empty then Display queue is empty otherwise display the items in queue. Step 8: if the option 4 is selected , it terminate the execution. Step 9: stop the execution

AIM: To create a queue using and do some operations like insert, remove and display using linked list . ALGORITHM: Step 1: Start the program. Step 2: Create a structure called node . Step 3: declare the variables and functions Step 4: assign rear = front = null . Step 5: If the option is 1then create a node with new pointer and allocate the Memory . a) get the item and store it in the information field . b) next field contain the address of the next node and assign rear = front = new when it is the first node otherwise assign rear = new . Step 6: if the option is 2 then check the queue is empty or not . if it is not the Front end of the item is deleted and point the front to the next node . Step 7: if the option 3 then check the queue is empty or not. If it is not . display the items of the queue . i)create a pointer temp to display the values . ii) assign the front pointer to temp and display the values by increment the pointer till it reaches null . Step 8:. stop the execution

AIM: To create a linked list and to do some operations like insert, delete and display . ALGORITHM: Step 1: Start the program. Step 2: Create a structure called node . Step 3: declare the variables and functions Step 4: assign list = null and head = null . Step 5: read the option . Step 6: if the option is 1 then create a list . a) get a node as pointer list . b) get the information . c) increment the count . d) assign head = list . Step 7: if the option 3 then insert item into first position . a) get the node and information . b) point the next field to the head node . c) assign head = list and increment the count .. Step 8 : if it is option 3 then insert item into any position . a) get the position , the node to be inserted . b) if the position is 1 then repeat the step 7. c) If the position is less than count+1 then get the information and the node . assign p = head . transverse the node to position 1 use a looping statement. Assign the pointer , the new node point to the next node of p. iv) P node point the new node. v) Increment the count . Step 9: if it is option 4 then insert item at the end of the list . a) use a looping statement transverse the 1st node to last node(p) b) get the node and information . c) next field of p point the new node & next field of new node as null . d) increment the count . Step 10: if it is option 6 then delete from first position . a) assign the node to be delete as q . b) transverse head to the next node . c) assign next field of q as null . d) decrement the count . Step 11: if it is position 7 then delete item from any position . a) get the position of node before the node to be deleted . b) if the position is 1 then repeat step 10 . c) if the position less than count+1 then i)assign p = head and transverse the node to position -1 and initialize the next node of p as q the node to be delete. i) ii) iii)

ii) assign the address of the next field of q to the previous node p. iii) assign the next field of deleted node(q) as null . iv) decrement the count. d) if the position equal to count then repeat step 12 . Step 12: if it is option 7 then delete node from the end of the list . a) assign p = head . b) traverse p to count 1 use a looping statement . c) assign the next node of p as q . d) Assign the next field of p as null . e) Decrement the count . Step 13: if the option is 8 then display all items in the list . a) check head equal to null or not . b) if not assign p = head . c) check p not equal to null print the item increment the pointer p till p reach to null . Step 14: stop the execution .

. AIM: To create a stack and do some operations like push , pop and display using linked list. Algorithm: Step 1: start the program. Step 2: create a structure called node. Step 3: declare variables and functions. Step 4: assign top=null. Step 5: read the option. Step 6:if the option is 1 , then create a node with new pointer and allocate the memory. a) get the item and store in information field b) next field contain the address of the next node and assign top=new. Step 7: if the option is 2 then check the stack is empty or not . if it is empty then print Empty otherwise the top of the information is deleted and point the top the next node Step 8: if the option is 3 then check the stack is empty or not. If it is not empty then Retrive the data from the top otherwise print empty. Step 9: if the option is 4 then display the values from the stack . create a pointer Display the values Assign the top pointer to temp and display the values by increment The pointer till it reaches NULL. Step 10: stop the execution.

You might also like