Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

ignus deoria the great city...why i am getting wrong??

$
0
0
#include<iostream>
using namespace std;

struct node
{

    int data;
    node *next;
};

node *head;
node *tail;
int count;

void push(int b,int n)
{

    node *x=new node;
    x->data=b;
    x->next=NULL;
    if(count==0)
    {
        head=x;
        tail=x;
    }
    else if(count>=n)
    {

            tail->next=x;
            tail=tail->next;
            head=head->next;
    }
    else
    {
            tail->next=x;
            tail=tail->next;
    }
}

bool search(int b)
{

    node *x;
    x=head;
    bool flag= false;
    if(x==NULL)
    {
        return flag;
    }
    while(x!=NULL)
    {
        if((x->data)==b)
        {
            flag=true;
            return flag;
        }
        x=x->next;
    }
    return flag;
}


void print()
{
    node *x;
    x=head;
    while(x!=NULL)
    {
        cout<<x->data<<" ";
        x=x->next;
    }
    cout<<"\n";
}






//main function
int main()
{

    int t,m,n,a,b;
    cin>>t;
    while(t--)
    {

        head=NULL;
        tail=NULL;
        cin>>n>>m;
        count=0;
        while(m--)
        {
            cin>>a>>b;
            if(a==1)
            {

                push(b,n);
                ++count;

            }
            if(a==2)
            {
                if(search(b))
                {
                    cout<<"YES\n";
                }
                else
                {
                    cout<<"NO\n";
                }
            }
        }

    }
    return 0;
}

Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>