Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define SIZE 10 /* Size of Stack */
- int CQ[SIZE],f=-1,r=-1; /* Global declarations */
- int s[SIZE],top=-1; /* Global declarations */
- void push(int elem)
- { /* Function for PUSH operation */
- if( Sfull()) printf("\n\n Overflow!!!!\n\n");
- else
- {
- ++top;
- s[top]=elem;
- }
- }
- int pop()
- { /* Function for POP operation */
- int elem;
- if(Sempty()){ printf("\n\nUnderflow!!!!\n\n");
- return(-1); }
- else
- {
- elem=s[top];
- top--;
- return(elem);
- }
- }
- int Sfull()
- { /* Function to Check Stack Full */
- if(top == SIZE-1) return 1;
- return 0;
- }
- int Sempty()
- { /* Function to Check Stack Empty */
- if(top == -1) return 1;
- return 0;
- }
- void displayStek()
- { /* Function to display status of Stack */
- int i;
- if(Sempty()) printf(" \n Empty Stack\n");
- else
- {
- for(i=0;i<=top;i++)
- printf("\n%d\n",s[i]);
- printf("^Top\n\n");
- }
- }
- void insert(int elem)
- { /* Function for Insert operation */
- if( CQfull()) printf("\n\n Overflow!!!!\n\n");
- else
- {
- if(f==-1)f=0;
- r=(r+1) % SIZE;
- CQ[r]=elem;
- }
- }
- int Delete()
- { /* Function for Delete operation */
- int elem;
- if(CQempty()){ printf("\n\nUnderflow!!!!\n\n");
- return(-1); }
- else
- {
- elem=CQ[f];
- if(f==r){ f=-1; r=-1;} /* Q has only one element ? */
- else
- f=(f+1) % SIZE;
- return(elem);
- }
- }
- int CQfull()
- { /* Function to Check Circular Queue Full */
- /* proverava se pre povećanja r*/
- if( (f==r+1) || (f == 0 && r== SIZE-1)) return 1;
- return 0;
- }
- int CQempty()
- { /* Function to Check Circular Queue Empty */
- if(f== -1) return 1;
- return 0;
- }
- void displayRed()
- { /* Function to display status of Circular Queue */
- int i;
- if(CQempty()) printf(" \n Empty Queue\n");
- else
- {
- printf("Front[%d]->",f);
- for(i=f;i!=r;i=(i+1)%SIZE)
- printf("%d ",CQ[i]);
- printf("%d ",CQ[i]);
- printf("<-[%d]Rear\n",r);
- }
- }
- void RedUmetanje()
- {
- int i;
- insert(2018);
- for(i=2;i<=7;i++)
- {
- insert(2018*i);
- }
- }
- void StekUmetanje()
- {
- int i;
- for(i=f;i!=r;i=(i+1)%SIZE)
- if(CQ[i]%5==0)
- push(CQ[i]);
- }
- int main()
- {
- RedUmetanje();
- displayRed();
- StekUmetanje();
- displayStek();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement