Hi I am using the forward list STL library in VS 2019. This is my block of code:
forward_list<int> fl1;
fl1.assign({ 1,2,3,4 });
fl1.push_front(0);
fl1.pop_front();
cout << "Front " << fl1.front() << endl;
forward_list<int>::iterator it4 = fl1.begin();
it4 = fl1.insert_after(it4, 5);
fl1.emplace_front(6);
fl1.remove(6);
forward_list<int> fl2;
fl2.assign({ 9,8,7,6,6 });
fl2.unique();
fl2.sort();
fl1.sort();
fl2.reverse();
fl1.merge(fl2);
// fl1.clear();
for (int i : fl1)
cout << i << endl;
Once the program hits the merge line, it gives me a "Debug Assertion Failed Line: 1492 Expression: Sequence not ordered" my code is only 500 lines long and the code itself occurs at line 342 where I have that for loop that is supposed to handle iterate through fl1: for (int i : fl1) cout << i << endl;
When I hit abort and see the debug error, it says "Unhandled exception at 0x5049F2F6 (ucrtbased.dll) in Derektut.exe: An invalid parameter was passed to a function that considers invalid parameters fatal"
Why is this?
merge(), the lists need to be sorted, and yourfl1list is not sorted. See the documentation - PaulMcKenziesortfunction sorts in ascending order, and your other list has descending sort order. How is that going to work? - PaulMcKenzie