LINKED LIST IMPLEMENTATION OF STACK
Aim
To
demonstrate linked list implementation of stack using a C program.
Algorithm
Step
1: [Include all the necessary header files]
Step
2: [Declare the Variables]
Step
3: Read operator
Step
4.1: READ n
Step
4.2.1: READ d
Step
4.2.2: CALL INSERT( start , d)
Step
4.3: [End of while Structure]
Step
5.1: READ x
Step
5.2: CALL del (start,x)
Step
6.1: READ x
Step
6.2: CALL FIND
Step
7.1: READ x
Step
7.2: CALL FINDPREVIOUS
Step
8.1: READ x
Step
8.2: CALL FINDNEXT(start, x)
CALL
len(Start)
CALL
printlist(Start)
CALL
erase (Start)
Step 12: [End of
Main ]
Algorithm For
Find(struct node*p, int x, int *pos)
RETURN
NULL
ELSE
ASSIGN
1 TO *POS+1 AND TEMP’S LLINK FIELD TO TEMP
RETURN
THE TEMP
Algorithm for Previous
(struct node*p, int x)
RETURN
NULL
ELSE
ASSIGN TEMP’S
LINK FIELD TO TEMP
RETURN
THE TEMP
Algorithm For Find
next(struct node*p, int x)
RETURN
NULL
ELSE
ASSIGN
TEMP’S LLINK FIELD TO TEMP
RETURN
THE TEMP’S LINK FIELD
Coding: