473,379 Members | 1,174 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,379 software developers and data experts.

delete element from list

hi,
if i create a linked list like list<char> stk;
if i want to remove the first element from the list and i write
stk.pop_front() the node is still present but the char stored is now
'\0',why? how can i delete the first node. will
stk.erase(stk.begin()) work?

Aug 29 '05 #1
3 7635
hi

this will work.

plz see
http://support.microsoft.com/kb/q158085/

for the same.

thanks
rt

Aug 29 '05 #2

ar*******@gmail.com schreef:
hi,
if i create a linked list like list<char> stk;
if i want to remove the first element from the list and i write
stk.pop_front() the node is still present but the char stored is now
'\0',why?


When you create the linked list like you do, it's empty. If you then
try to remove an element, you get Undefined Behavior. Anything is OK.
If on your compiler the result is size()==1 and front()==\0, then
that's what UB meant - on that occasion. Don't count on it, UB is
unpredictable in the extreme.

Solution: before removing the first element, check if it exists.
( !empty() )

HTH,
Michiel Salters

Aug 29 '05 #3
<ar*******@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
if i create a linked list like list<char> stk;
if i want to remove the first element from the list and i write
stk.pop_front() the node is still present but the char stored is now
'\0',why? how can i delete the first node. will
stk.erase(stk.begin()) work?


Please show us some code that you think is not working correctly. It's hard
to make sense of your description of the problem.
Aug 29 '05 #4

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

Similar topics

9
by: Birgit Rahm | last post by:
Hello newsgroup, I am a beginner, so I am asking maybe immoderate questions. I want to delete a variable, after filling it with complex objects. How should I do it? e.g. AAA = AAA = Can I...
14
by: Timothy Madden | last post by:
Hello I have a linked list of object of a class. I thought it would be nice to have the destructor delete the whole list when I delete just the first element. I don't want to recursivly destroy...
13
by: Nemo | last post by:
Hello Folks, I need to manipulate a list of char strings as follows, but when I want to delete the pointer created with new at the end, delete operator crashes, any idea? char* list;...
7
by: python | last post by:
after del list , when I use it again, prompt 'not defined'.how could i delete its element,but not itself? except list.remove(val) ,are there other ways to delete list 's elements? and , I...
7
by: Yi | last post by:
Two questions about the following code sample: --- code begins --- //class IPv4 is defined elsewhere list<IPv4ip_list; for (int i=1; i<=9; i++) { char addr; sprintf(addr, "%d.%d.%d.%d",...
2
by: mathon | last post by:
hello, i thought i create a new topic for that because i deal with a certain problem. I have implemented all methods for a LinkdeList (for my sequence class) and tested all correct. Now i only...
5
by: streamkid | last post by:
i have a class table, which has a vector of records(-db). i 'm trying to remove an element, but it doesn't seem to work.. i read this http://www.cppreference.com/cppvector/erase.html] and that's...
3
by: AbrahamLincolnIllinois | last post by:
Hi all. I have a list of pointers to a complicated object. When I erase() a member of that list, the little blob of memory that contains the pointer is deleted, I think. But the object pointed...
7
by: =?utf-8?B?5YiY5piK?= | last post by:
Hi, folks, Is it possible to delete an element from a sorted array with O(1) time? Best regards
3
by: Barkingmadscot | last post by:
I am stuck, i can workout how to remove lines from an array I have loading a text file (a Log), I know which lines a need, but the logs can be upto 30K sometimes bigger. I found trying to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.