473,394 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

what is the error

jw
//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;
}
}

}

Dec 8 '05 #1
2 976
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
Dec 8 '05 #2
jw

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


Dec 8 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
4
by: atv | last post by:
Whatis the proper way to handle errors from function calls? For example, i normally have a main function, with calls to mine or c functions. Should i check for errors in the functions called...
6
by: Daniel Rudy | last post by:
What is wrong with this program? When I try to compile it, I get the following error. Compiler is gcc on FreeBSD. strata:/home/dcrudy/c 1055 $$$ ->cc -g -oe6-3 e6-3.c e6-3.c: In function...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
10
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
4
by: brian | last post by:
i broke down where i think the problems areas would be. any help would be greatly appreciated. where the file is called <script type="text/javascript" src="k.js"> </script> the beginning...
4
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
9
by: Trent | last post by:
Here is the error while using Visual Studio 2005 Error 1 error LNK2019: unresolved external symbol "void __cdecl print(int,int,int,int,int,int,int,int)" (?print@@YAXHHHHHHHH@Z) referenced in...
5
by: =?GB2312?B?17/HvyBaaHVvLCBRaWFuZw==?= | last post by:
Hi, I would like to have someone comments on what's the best practice defining error codes in C. Here's what I think: solution A: using enum pros: type safe. better for debug (some debugger...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.