Write a
function to insert a number into a sorted linked list. Assume the list is
sorted from smallest to largest value. After insertion, the list should still
be sorted. Given the list l1 = (3, 17, 18, 27) and the value 20, on return l1
be the list (3, 17, 18, 20, 27).
<iostream>
#include <list>
int main ()
{
std::list<int> l1 = {3, 17, 18, 27};
l1.push_back(20);
l1.sort();
for(auto& el: l1)
{
std::cout<<el<<'\t';
}
std::cout<<std::endl;
}
Comments
Leave a comment