Answer to Question #284011 in C++ for ahmed

Question #284011

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).


1
Expert's answer
2021-12-31T15:43:30-0500
 <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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog