Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what is the error

Reply
Thread Tools

what is the error

 
 
jw
Guest
Posts: n/a
 
      12-08-2005
//a single link list,the nodes contain an integer value called value
void handler::delete(){
int del;
cout<<"which number do u want to delete"<<endl;
cin>>del;
node *previous;//always behind the sth node

for(node *sth=head;sth!=NULL;sth=sth->next){
if(sth->value==del)
{
if(sth==head)
{
node *deleted=head;
head=head->next;
delete deleted;
}

else
{
node *deleted=sth;
previous->next=deleted->next;
delete deleted;
}
previous=sth;
}
}



}

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      12-08-2005
jw wrote:
> //a single link list,the nodes contain an integer value called value
> void handler::delete(){
> int del;
> cout<<"which number do u want to delete"<<endl;
> cin>>del;
> node *previous;//always behind the sth node
>
> for(node *sth=head;sth!=NULL;sth=sth->next){


Drop the last statement in the parentheses:

for (node *sth = head; sth != NULL {

> if(sth->value==del)
> {
> if(sth==head)
> {
> node *deleted=head;
> head=head->next;
> delete deleted;


If you want to delete all elements with value 'del', then you should stay
here and make sure you check all elements that can become heads:

sth = head;
continue;

If you only want to delete the very first one, you should bail out:

break;

> }
>
> else
> {
> node *deleted=sth;
> previous->next=deleted->next;
> delete deleted;


Same question: do you want to continue looking for value 'del'? Decide,
and then add the necessary things here.

> }
> previous=sth;


Add
sth = previous->next;

> }
> }
>
>
>
> }
>


V
 
Reply With Quote
 
 
 
 
jw
Guest
Posts: n/a
 
      12-08-2005

Victor Bazarov wrote:
> jw wrote:
> > //a single link list,the nodes contain an integer value called value
> > void handler::delete(){
> > int del;
> > cout<<"which number do u want to delete"<<endl;
> > cin>>del;
> > node *previous;//always behind the sth node
> >
> > for(node *sth=head;sth!=NULL;sth=sth->next){

>
> Drop the last statement in the parentheses:
>

i want to delete a node whose value is del so..
> for (node *sth = head; sth != NULL {

this statement searches the list the node which ll be deleted might be
at the head or somewhere else
>
> > if(sth->value==del)
> > {
> > if(sth==head)
> > {
> > node *deleted=head;
> > head=head->next;
> > delete deleted;

>
> If you want to delete all elements with value 'del', then you should stay
> here and make sure you check all elements that can become heads:
>
> sth = head;
> continue;
>
> If you only want to delete the very first one, you should bail out:
>
> break;
>
> > }
> >
> > else
> > {
> > node *deleted=sth;
> > previous->next=deleted->next;
> > delete deleted;

>
> Same question: do you want to continue looking for value 'del'? Decide,
> and then add the necessary things here.
>
> > }
> > previous=sth;

>
> Add
> sth = previous->next;
>
> > }
> > }
> >
> >
> >
> > }
> >

>
> V


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments