Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7619309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:39:20+00:00 2026-05-31T03:39:20+00:00

i want to traverse a list and delete elements greater than 30 QList<double> mylist;

  • 0

i want to traverse a list and delete elements greater than 30

QList<double> mylist;
QList<double>::iterator myiterator = mylist.begin();

mylist.append(6);
mylist.append(36);

myiterator=mylist.begin();
while(myiterator!=mylist.end())
{
    if(*(myiterator)>30)
    {
        QList<double>::iterator next=myiterator;
        next++;
        mylist.erase(myiterator);
        myiterator=next;

    }
    else
        myiterator++;

    if(myiterator==mylist.end())
        std::cout<<"end of list "<<std::endl;
    else
        std::cout<<" not end of list "<<std::endl;
}

output is

 not end of list 
 not end of list 
The program has unexpectedly finished.
/home/maverik/Desktop/Qt/container_class/container_class exited with code 0

where as if i make mylist = {36,34} or mylist = {36,9} or mylist={9,10} then output is

 not end of list 
end of list 

the error only comes when the last element is greater than 30 or if greater but the 1st element is also greater than 30

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:39:21+00:00Added an answer on May 31, 2026 at 3:39 am

    Like the C++ standard containers erase returns an iterator to the element after the deleted one, so that part of your loop should be quite simple:

     if((*myiterator)>30)
        myiterator = mylist.erase( myiterator );
     else
        myiterator++;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of elements in Erlang, and I'm using lists:foreach to traverse
I want to be able to traverse through a list of DataRow using For
After getting a List<dynamic> object from the linq query, I want to traverse through
I'm having the following issue - I want to traverse all the xml files
i am currently implementing a binary tree in c++ and i want to traverse
I want to override the selection behavior of ListBox Items. We can traverse through
want to know why String behaves like value type while using ==. String s1
I'm trying to figure out how to traverse a generic list of items that
I have got the list of my friends and i can traverse through the
I have a dictionary to which I want to append to each drug, a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.