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
Machine Problem 3 - Linked List C++ For this assignment you will write a program that...
Machine Problem 3 - Linked List C++ For this assignment you will write a program that inserts 20 random integers from 0 to 100 in order in a linked list object. The program will create another linked list, but with 15 random integers from 0 – 100 in order. The program then will merge those two ordered linked list into a single ordered list. The function merge should receive references to each of the list objects to be merged and...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs...
Task 2: Compare strings. Write a function compare_strings() that takes pointers to two strings as inputs and compares the character by character. If the two strings are exactly same it returns 0, otherwise it returns the difference between the first two dissimilar characters. You are not allowed to use built-in functions (other than strlen()) for this task. The function prototype is given below: int compare_strings(char * str1, char * str2); Task 3: Test if a string is subset of another...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
Please write code in C++ and include headers files not std/bitsc: (Pattern matching) Write a program...
Please write code in C++ and include headers files not std/bitsc: (Pattern matching) Write a program that prompts the user to enter two strings and tests whether the second string is a substring in the first string. Suppose the neighboring characters in the string are distinct. Analyze the time complexity of your algorithm. Your algorithm needs to be at least O(n) time. Sample Run Enter a string s1: Welcome to C++ Enter a string s2: come matched at index 3
Write a Python program to create a dictionary from two lists without losing duplicate values. If...
Write a Python program to create a dictionary from two lists without losing duplicate values. If there is more values in the key list, then provided key should return an empty set if there is no match. (Hint: use defaultdict) Example: class_list = ['Class-V', 'Class-VI', 'Class-VII', 'Class-VIII','Class-IX'] id_list = [1, 2, 2, 3] Output: assuming you store the values in a data structure named temp print(temp["Class-V"]) # {1} print(temp["Class-IX"]) # set() can you please try and do on google colab
C LANGUAGE Create your own library named cis340yourlastname. Create a header file named cis340yourlastname. Write a...
C LANGUAGE Create your own library named cis340yourlastname. Create a header file named cis340yourlastname. Write a program that receives two numbers from the user and uses your written library to calculate the reminder after division, the addition, and the subtraction of these two input numbers. (Hint your library should include three functions. Your header file should not contain the code for any of these functions, it should contain only the instructions for how to use the library).
Write a PYTHON program for the following: A dictionary courses lists summer school classes a student...
Write a PYTHON program for the following: A dictionary courses lists summer school classes a student is taking, along with information about the classes. For example, courses = { "CS 101" : { "full_name" : "Intro to CS with Python", "instructors" : [ "Sally", "Johnson" ], "tas" : ["Bob", "Joe",..., "Elroy"], "num_homeworks" : 6, "num_exams" : 2 }, "SPAN-SAA" : { "name" : "Beginning Spanish I", ... }, ... } Write a loop that computes the total number of homeworks...
Given two sorted lists, L1 and L2, write a procedure to compute L1 ∪ L2 using...
Given two sorted lists, L1 and L2, write a procedure to compute L1 ∪ L2 using only the basic list operations.
Given two sorted lists, L1 and L2, write a procedure to compute L1 ∩ L2 using...
Given two sorted lists, L1 and L2, write a procedure to compute L1 ∩ L2 using only the basic list operations.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT