priority Queue using arrays

 #include<bits/stdc++.h>
using namespace std;
int min_key(int arr[], int s, bool accepted[])
{
    int mn=100,min_index,i;
    for(i=0;i<s;i++)
    {
        if(arr[i]<mn && accepted[i]==false)
        {mn=arr[i];
        min_index=i;}
    }
    return min_index;
}

int main()
{
    int s,i,mn,j,q,t,out_index;
    cout<<"Enter the size of queue";
    cin>>s;
    int que[3][s];
    cout<<"Enter the querries : ";
    //data//inpriority//outpriority
    int arr[s],inp[s],oup[s];
    bool inserted[s], removed[s];
    for(i=0;i<q;i++)
    {
        inserted[i]=false;
        removed[i]=false;
        cout<<"enter data : ";
        cin>>arr[i];
        cout<<"Enter in priority : ";
        cin>>inp[i];
        cout<<"Enter the out priority : ";
        cin>>oup[i];
    }

    ///insertion///
    int rear=-1;
    for(i=0;i<s;i++)
    {
        mn=min_key(inp,s,inserted);
        que[i][++rear]=arr[mn];
        que[i+1][rear]=inp[mn];
        que[i+2][rear]=oup[mn];
        inserted[mn]=true;
    }

    ///deletion//
    //size will decrease by t//
    for(i=0;i<s;i++)
    {
        t=0;
        mn=min_key(oup,s,removed);
        removed[mn]=true;
        for(j=0;j<s-t;j++)
        if(que[0][j]==arr[mn])
        out_index=j;
        for(j=out_index;j<s-t-1;j++)
        {
            que[0][j]=que[0][j+1];
            que[1][j]=que[1][j+1];
            que[2][j]=que[2][j+1];
        }
        t+=1;
    }

    
}

Comments

  1. Thanks bro suggestion for this topic and again thank you
    Educational topic
    roj Dala karo

    ReplyDelete

Post a Comment

Popular posts from this blog

First_Come_First_Serve CPU Scheduling

Reversing stack Method 2 !! (One Helper Stack only)

Populating Next Right Pointers in Each Node in O(1) space (without queue and level order)

Calculate factorial of large numbers !! (Using Arrays)

Multiplication of large numbers (Given in string format)

Left View of Binary Tree (Method 1 using recursion)

Check Bracket Sequence

Image Multiplication

Boundary Traversal of binary tree

BST to greater sum tree