Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

plz plz help me to solve this errors in linklist code..

vnayakvnayak Member Posts: 16
Hi everyone..
As i posted before i am working on the linklist program of self oraganizing.The whole data i have posted before but noone reply me so i am posting it again...the code is[code][/code]
#include
using namespace std;


struct node
{ char item[20];
int id;
int num_items;
node *nxt;
};

node *start_ptr = NULL;
node *current;
int option = 0;

void add_node_at_end()
{ node *temp, *temp2;


temp = new node;
cout << "Please enter the item : ";
cin >> temp->item;
cout << "Please enter the ID number of the item: ";
cin >> temp->id;

temp->nxt = NULL;

// Set up link to this node
if (start_ptr == NULL)
{ start_ptr = temp;
current = start_ptr;
}
else
{ temp2 = start_ptr;

while (temp2->nxt != NULL)
{ temp2 = temp2->nxt;

}
temp2->nxt = temp;
}
}

void display_list()
{ node *temp;
temp = start_ptr;
cout << endl;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{ while (temp != NULL)
{
cout << "item : " << temp->item << " ";
cout << "ID : " << temp->id << " ";

if (temp == current)
cout << " <-- Current node";
cout << endl;
temp = temp->nxt;

}
cout << "End of list!" << endl;
}
}

void delete_start_node()
{ node *temp;
temp = start_ptr;
start_ptr = start_ptr->nxt;
delete temp;
}

void delete_end_node()
{ node *temp1, *temp2;
if (start_ptr == NULL)
cout << "The list is empty!" << endl;
else
{ temp1 = start_ptr;
if (temp1->nxt == NULL)
{ delete temp1;
start_ptr = NULL;
}
else
{ while (temp1->nxt != NULL)
{ temp2 = temp1;
temp1 = temp1->nxt;
}
delete temp1;
temp2->nxt = NULL;
}
}
}



void search(){
node *tmp;
//char item[20];
int n;
cout<<"
*****Search*****
";
cout<<" Enter data to be searched : ";
cin>> tmp->id;
for(tmp=start_ptr,n=1; tmp!=NULL; tmp=tmp->nxt,n++)
{
if(tmp->nxt== tmp->id)

{
cout<<"
Search is located at "<<n<<" location";
}
else
{

cout<<"
Search Not Found";
}

}
}

int main()
{ start_ptr = NULL;

do
{
display_list();
cout << endl;
cout << "Please select an option : " << endl;
cout << "0. Exit the program." << endl;
cout<<" 1.Insert a new item."<<endl;
cout <<" 2.Find and print the id and count for a particular item."<<endl;
cout <<" 3.Delete an item."<<endl;
// cout <<" 4.Print the list in self-organizing order "<<endl;
// cout << "5.Print the list in reverse self-organizing order "<<endl;
// cout << "6.Print the list in sorted order based on the id. "<<endl;

cout << endl << " >> ";
cin >> option;

switch (option)
{
case 1 : add_node_at_end(); break;
case 2: display_list();break;
case 3 : delete_start_node();
// case 4:print_list();break;
// case 5:print_reverse();break;
// case 6:print_sortedID();
}
}
while (option != 0);
return 0;
}



I got the errors ..

error C2446: '==' : no conversion from 'int' to 'node *'
error C2040: '==' : 'node *' differs in levels of indirection from 'int'

which i dont resolved plz anyone who does know this plz try to reply me..thanks...




Comments

  • LundinLundin Member Posts: 3,711
    if(tmp->nxt== tmp->id)

    should probably be

    if(tmp->nxt->id == tmp->id)
  • vnayakvnayak Member Posts: 16
    : if(tmp->nxt== tmp->id)
    :
    : should probably be
    :
    : if(tmp->nxt->id == tmp->id)
    Hi lundin..
    Thanks for ur reply.
    I have changed the things that you had suggested me .Actually i have modified my code thatsway when i changed it again shows me errors.Could you plz suggest me where i am making mistake.Plz plz reply me it would be ur greatest help.[code][/code]

    #include
    using namespace std;


    struct node
    {
    int id;
    int num_items;
    node *nxt;
    //node *l;

    }*list;

    node *start_ptr = NULL;
    node *current;
    node*l;
    int option = 0;

    void add_node_at_end()
    { node *temp, *temp2;


    temp = new node;

    cout << "Please enter the ID number of the item: ";
    cin >> temp->id;

    temp->nxt = NULL;

    // Set up link to this node
    if (start_ptr == NULL)
    { start_ptr = temp;
    current = start_ptr;
    }
    else
    { temp2 = start_ptr;

    while (temp2->nxt != NULL)
    { temp2 = temp2->nxt;

    }
    temp2->nxt = temp;
    }
    }

    void display_list()
    { node *temp;
    temp = start_ptr;
    cout << endl;
    if (temp == NULL)
    cout << "The list is empty!" << endl;
    else
    { while (temp != NULL)
    {

    cout << "ID : " << temp->id << " ";

    if (temp == current)
    cout << " <-- Current node";
    cout << endl;
    temp = temp->nxt;

    }
    cout << "End of list!" << endl;
    }
    }

    void delete_start_node()
    { node *temp;
    temp = start_ptr;
    start_ptr = start_ptr->nxt;
    delete temp;
    }

    void delete_end_node()
    { node *temp1, *temp2;
    if (start_ptr == NULL)
    cout << "The list is empty!" << endl;
    else
    { temp1 = start_ptr;
    if (temp1->nxt == NULL)
    { delete temp1;
    start_ptr = NULL;
    }
    else
    { while (temp1->nxt != NULL)
    { temp2 = temp1;
    temp1 = temp1->nxt;
    }
    delete temp1;
    temp2->nxt = NULL;
    }
    }
    }


    void search(){
    node *tmp;
    int n;

    cout<<" Enter data to be searched : ";
    cin>> tmp->id;
    for(tmp=start_ptr,n=1; tmp!=NULL; tmp=tmp->nxt,n++)
    {
    if(tmp->nxt->id== tmp->id)

    {
    cout<<"
    Search is located at "<<n<<" location";
    }
    else
    {

    cout<<"
    Search Not Found";
    }

    }
    }





    int count()
    {
    int ct=0;
    current = start_ptr;
    while (current != NULL)
    {
    ct++;
    current = current->nxt;
    }
    return(ct);
    }

    void print ()
    {
    node *ptr = l ;
    while ( ptr != NULL )
    {
    cout << endl << ptr->id << endl;
    ptr = ptr -> nxt;
    }
    }





    int main()
    { int n,ID,print;
    start_ptr = NULL;

    do
    {
    display_list();
    cout << endl;
    cout<<"Please select an option : " << endl;
    cout<<"0.Exit the program." << endl;
    cout<<"1.Insert a new item."<<endl;
    cout<<"2.display the list"<<endl;
    cout<<"3.search"<<endl;
    cout<<"4.Delete an item."<<endl;
    cout<<"5.count the node"<<endl;

    cout <<" 6.Print the list in self-organizing order "<<endl;
    // cout << "5.Print the list in reverse self-organizing order "<<endl;
    // cout << "6.Print the list in sorted order based on the id. "<<endl;

    cout << endl << " >> ";
    cin >> option;

    switch (option)
    {
    case 1 : add_node_at_end(); break;
    case 2: display_list();break;
    case 3 :
    search();
    case 4 : delete_start_node();break;
    case 5:printf("
    There are %d Nodes in the Linked List",count());
    // case 6:printf("print",print());
    // case 5:print_reverse();break;
    // case 6:print_sortedID();
    }
    }
    while (option != 0);
    return 0;
    }

    You can compile it but when you debug it,it shows you debug error.It says
    temp used without being define but i dont know why it shows me bec i have defined it.
    Plz plz let me know if you can find errors..




Sign In or Register to comment.