Question

Write a program that uses Standard Library algorithm to merge two ordered lists of strings into...

  1. Write a program that uses Standard Library algorithm to merge two ordered lists of strings into a single ordered list of strings, then displays the resulting list.

Homework Answers

Answer #1

Hope the solution helps. I am using C++ as there is no language preference

#include <iostream>
#include <list>
#include <string>

using namespace std;

int main() {
    //In the program we are using list. It is a data structure which helps us to merge two list easily
    list<string> s1;
    list<string> s2;
    string a = "aasd";
    string b = "bdds";
    string c = "csd";
    string d = "dsd";
    string e = "efds";
    s1.push_back(a);
    s1.push_back(d);
    s1.push_back(e);
    s2.push_back(b);
    s2.push_back(c);


    s2.merge(s1);
    s2.sort(); //Sort the list according so that the items get ordered
 

    for (auto i : s2) {
        cout << i << " ";
    }
    cout << "\n";
}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write an algorithm to check equality of two link lists. IN JAVA OR PSEUDOCODE
Write an algorithm to check equality of two link lists. IN JAVA OR PSEUDOCODE
Write an application that prompt user to choose Sorting Algorithm (Insertion, Merge, or Heap) in GUI...
Write an application that prompt user to choose Sorting Algorithm (Insertion, Merge, or Heap) in GUI input message, then prompt user to enter numbers in GUI input message also, sort these numbers in descending order using Selected sorting algorithm, and show the result in message dialog as shown in the following figure. The program contains two classes: 1- “Sort” Class which contains 3 methods named as follow: a. InsertionSort(int[] numbers), returns sorted numbers from the passed array using Insertion sort...
Write a program in Python to declare two empty lists one is for name and one...
Write a program in Python to declare two empty lists one is for name and one for salaries. Within the for loop ask for employees name and their salaries and append them into the list accordingly. Find out the total salary using accumulation concept within the for loop. Output : Both of the lists with their items and the total salary.
Write a java program that reads two sentences as strings, the program should print the common...
Write a java program that reads two sentences as strings, the program should print the common terms in both sentences example: input: I did my java homework yesterday yesterday i went to java island
THIS QUESTION HAS TWO PARTS: A) Write an application that accepts three Strings from the user...
THIS QUESTION HAS TWO PARTS: A) Write an application that accepts three Strings from the user and displays one of two messages depending on whether the user entered the Strings in alphabetical order without regard to case. Save the file as Alphabetize.java. B) Write an application that accepts three Strings from the user and displays them in alphabetical order without regard to case. Save the file as Alphabetize2.java
In C++ write a program for a multiplication table It must Prompt the user for two...
In C++ write a program for a multiplication table It must Prompt the user for two integers between 1 and 20 (inclusive) • also must Calculates and displays the multiplication table in a well-formatted output The table must include a label for each row and column The program must follow the requirements: • Validates user input, displaying an error message and prompting to user to enter another integer if the input is invalid, and repeating it as many times as...
Python: Write a program that performs a logarithmic search on an ordered list of 1000 elements....
Python: Write a program that performs a logarithmic search on an ordered list of 1000 elements. The search on the list should be on a randomly generated number between 1-1000.
Python: Write a program that performs a sequential search on an ordered list of 1000 elements....
Python: Write a program that performs a sequential search on an ordered list of 1000 elements. The search on the list should be on a randomly generated number between 1-1000.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT