0

Okay so i get the error no matching function for call to Queue::insert(int&). I dont really get what this means. Im just trying to take the contents from a text file and put it into the linked list. The text file looks like this:

AAABBBAAA aaaa ABAABBBBAAAA BBBB BBAABB BBAAABB

I want it to put each line into the linked list. im thinking a for loop would be right but everytime i try to do what im trying to do i get the error from above.

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

struct Node{
    string data;
    Node *next;
};

class Queue{
    public:
    Node *front,*rear;
    Queue(){front=rear=NULL;}

    void insert(string n);
    void deleteitem();
    void display();
    ~Queue();
};

void Queue::insert(string n){
    Node *temp=new Node;
    if(temp==NULL){
        cout<<"Overflow"<<endl;
        return;
    }
    temp->data=n;
    temp->next=NULL;

    //for first node
    if(front==NULL){
        front=rear=temp;
    }
    else{
        rear->next=temp;
        rear=temp;
    }
    cout<<n<<" has been inserted successfully."<<endl;
}

void Queue::display(){
    if(front==NULL){
        cout<<"Underflow."<<endl;
        return;
    }
    Node *temp=front;
    //will check until NULL is not found
    while(temp){
        cout<<temp->data<<" ";
        temp=temp->next;
    }
    cout<<endl;
}

void Queue :: deleteitem()
    {
    if (front==NULL){
        cout<<"underflow"<<endl;
        return;
    }

    cout<<front->data<<" is being deleted "<<endl;
    if(front==rear)//if only one node is there
        front=rear=NULL;
    else
        front=front->next;
}

Queue ::~Queue()
{
    while(front!=NULL)
    {
        Node *temp=front;
        front=front->next;
        delete temp;
    }
    rear=NULL;
}


int main(){


    ifstream file;

    file.open("exp.txt");

    Queue Q;

    Q.display();
    for(int i = 0; i<5; i++)
    {
          (Q.insert(i));
    }

/*
    Q.insert(10);
    Q.insert(24);
    Q.insert(28);
    Q.insert(32);
    Q.insert(30);
*/
    Q.display();

    Q.deleteitem();
    Q.deleteitem();
    Q.deleteitem();
    Q.deleteitem();
    Q.deleteitem();

    return 0;
}

0 Answers0