Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.8 kB
4
Indexable
Never
//Please do not modify the header files.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

int size=1000000;

class Queue
{
    public:
        int dequeue(int q[], int start, int end);
        bool enqueue(int q[], int start, int end);
        bool isempty(int q[], int start, int end);
    
};

bool Queue::isempty(int q[], int start, int end)
{
    if(start==end) // start and end points to -1 in the beginning and we use the logic : start points to 1st elt and end points to last elt 
    {
        cout<<"Queue is empty";
        return true;
    }
    else
        return false;
}

int Queue::dequeue(int q[], int start, int end)
{
    if(start==end) // as start will pt to -1 and end will pt to 0 in the beginning (when no elts); and another case will be the one where start ptr is at the end and end at the 0th index
    {
        cout<<"Queue is empty";
        return -1;
    }
    else
    {
        int a=q[start];
        start=(start+1)%size;
        return a;
    }
}

bool Queue::enqueue(int q[], int start, int end, int elt)
{
    if((start<end && (start==0 && end==size-1)) || (start>end && start==end+1))
    {
        cout<<"Queue is full";
        return false;
    }
    else
    {
        end=(end+1)%size;
        q[end]=elt;
        return true;
    }
}

void findneighbouringcoordinates(int x, int y, int q1[], int q2[], int start1, int end1, int start2, int end2) //q1 and q2 are the queue to store neighbouring coordinates of (x,y)
{
    Queue Q;
    if(x-1>=0) //(x-1,y)
    {
        Q.enqueue(q1,start1, end1, x-1);
        Q.enqueue(q2,start2, end2, y); 
    }
    if(x+1<size)//for (x+1,y)
    {
        Q.enqueue(q1,start1, end1, x+1);
        Q.enqueue(q2,start2, end2, y);    
    }
    if(y+1<size)//for (x,y+1)
    {
        Q.enqueue(q1,start1, end1, x);
        Q.enqueue(q2,start2, end2, y+1);    
    }
    if(y-1>=0)//for (x,y-1)
    {
        Q.enqueue(q1,start1, end1, x);
        Q.enqueue(q2,start2, end2, y-1);    
    }
}

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 
    Queue Q;
    int m, int n;
    cin>>m>>n;
    int arr[m][n];
    
    int q1[size], q2[size]; //2 queues
    int start1=-1, end1=0, start2=-1, end2=0;
    for(int i=0;i<m;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>A[i][j];
            if(A[i][j]==2)
            {
                Q.enqueue(q1,start1,end1,i);
                Q.enqueue(q2,start2,end2,j);
            }
        }
    }
    
    int n=start1<end1 ?(end1-start1):(size1-start1+end1); //finding no of elts in the queue
    for(int i=0;i<n;i++)
    {
        
    }
    return 0;
}