STL:Standard Temparary Library
In RAM and we have a stack memory !
Now in Programming we store our data in stack or queue . and we implements these
using data structure
1)Array
or
2)Link List
or
3)Trees.
all these data structures are interconnected .you can create array to queue ,queue to array
Stack
Operations on stack
--Exbhibit LIFO (Last in first out)
--Here in stack we have have one pointer only
Push
S-our stack array
N-size of our stack array
Top-stack pointer
x-element to be pushed
Queue
Operations on queue
--Here in an array of queue we have two pointer
In RAM and we have a stack memory !
Now in Programming we store our data in stack or queue . and we implements these
using data structure
1)Array
or
2)Link List
or
3)Trees.
all these data structures are interconnected .you can create array to queue ,queue to array
Stack
Operations on stack
- Push
- Pop
- Is Full
- Is Empty
--Exbhibit LIFO (Last in first out)
--Here in stack we have have one pointer only
- Top
Push
S-our stack array
N-size of our stack array
Top-stack pointer
x-element to be pushed
- push(S,N,Top,x)
- {
- if(Top+1==N)
- {
- printf("Stack Overflow");
- exit;
- }
- else
- {
- Top++;
- S[Top]=x;
- }
Pop
--here we are only delecting the top most element of stack array S. as here we what to return the elemet which would be de;leted so for that we will use int return type of following function
- int pop(S,N,Top)
- {
- int y;
- if (Top==-1)
- {
- printf("Stack Underflow");
- exit;
- }
- else
- {
- y=S[Top];
- Top--;
- return y;
- }
Queue
Operations on queue
- Enqueue-Data Insert <--->Push in stack
- Dequeue- Data Delete
- Is Full
- Is Empty
--Here in an array of queue we have two pointer
- front--Tells deletion
- rear--Tells insertion
Enqueue
in below code
Q-Our Array
N-Size of our array
F-Front pointer of our queue
R-Rear pointer of our queue
x-element we want to put
- void enqueue(Q,N,F,R,x)
- {
- if(R+1==N) //means if R+1 ==size of an array
- {
- printf("Queue is overflow");
- exit;
- }
- else if
- {
- if(F==R==-1)
- {
- F=R=0;
- }
- else
- {
- R=R+1;
- }
- Q[R]=x;
- }
Dequeue
Here no x .because our aim is to just delete one element which is always from front and we also want what is the value of deleted array that's why we are returning from our function.
------------------------------------
^ ^
Front Rear(insertion)
(Deletion)
- int dequeue(Q,N,F,R)
- {
- int y;
- if(F==R==-1)
- {
- prinf("underflow");
- exit;
- }
- else
- {
- y=Q[F]; //delete
- if (F==R) //means in case if all element is before F is already deleted i.e null and we
- //know after R there is nothing So , Both R & F vacant in makes no sense so
- //to get rid of that Awkward situation we are placing both in front.And
- {
- F=R=-1;
- }
- else
- F=F+1;
- return y;
- }
- }
No comments:
Post a Comment