Write a program that lists all ways people can line up for a photo (all permutations of a list of strings). The program will read a list of one word names (until -1), and use a recursive method to create and output all possible orderings of those names, one ordering per line.
When the input is:
Julia Lucas Mia -1
then the output is (must match the below ordering):
Julia Lucas Mia Julia Mia Lucas Lucas Julia Mia Lucas Mia Julia Mia Julia Lucas Mia Lucas Julia
partial code below, only lines 9-11, and 18 can be added onto, the rest must stay the same.
#include <
#include <string>
#include <iostream>
using namespace std;
// TODO: Write method to create and output all permutations of the list of names.
void AllPermutations(const vector<string> &permList, const vector<string> &nameList) {
}
int main(int argc, char* argv[]) {
vector<string> nameList;
vector<string> permList;
string name;
// TODO: Read in a list of names; stop when -1 is read. Then call recursive method.
return 0;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 4 images
- Write a program that lists all Fibonacci numbers that are less than or equal to the number k (k≥2) entered by the user. Definition:The Fibonacci sequence is a sequence of numbers in which each additional term is the sum of the previous two. It is based on the fact that each member of the sequence is formed by the sum of the previous two members, the sequence starting with the numbers 1 and 1. (Example 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233 , 377, 610, 987 write program in c languagearrow_forwardThe Fibonacci algorithm is a famous mathematical function that allows us to create a sequence of numbers by adding together the two previous values. For example, we have the sequence:1, 1, 2, 3, 5, 8, 13, 21…Write your own recursive code to calculate the nth term in the sequence. You should accept a positive integer as an input, and output the nth term of the sequence.Once you have created your code, add comments describing how the code works, and the complexity of any code you have created.arrow_forwardGiven a long string use recursion to traverse the string and replace every vowel (A,E,I,O,U) with an @ sign. You cannot change the method header. public String encodeVowels(String s){ // Your code here }arrow_forward
- Pythonarrow_forwardA palindrome is a string that reads the same forward and backward. For example,“deed” and “level” are palindromes. Write an algorithm in pseudocode that testswhether a string is a palindrome. Implement your algorithm as a static method inJava. The method should call itself recursively and determine if the string is apalindrome.Write a main method that reads a string from the user as input and pass it to thestatic method. You need to validate the string and make sure it contains only letters(no digits or special characters are allowed). The main method should displaywhether the string is a palindrome or not. a) Read the string from the user and validate it.b) Create a method that calls itself recursively and returns whether thestring is a palindrome or not.c) Include a test table with at least the following test cases:1. Invalid input. For example, string contains a number or specialcharacter.2. A valid string that is a palindrome.3. A valid string that is not a palindrome.arrow_forwardThe Eight Queen Problem is to find a solution to place a queen in each row on a chessboard such that no queens can attack each other. write a program to solve the eight queen problem using the recursion and display the result. Program in javaarrow_forward
- python 3 Write a program that lists all ways people can line up for a photo (all permutations of a list of strings). The program will read a list of one word names, then use a recursive method to create and output all possible orderings of those names, one ordering per line. When the input is: Julia Lucas Mia then the output is (must match the below ordering): Julia Lucas Mia Julia Mia Lucas Lucas Julia Mia Lucas Mia Julia Mia Julia Lucas Mia Lucas Julia question: is it any way that i can use ('if' statement as base case, and 'else' statement as recursive case) in the code below? thanks. code: def all_permutations(permList, nameList):# TODO: Implement method to create and output all permutations of the list of names.def createPermutationsList(nameList):f = len(nameList) if f == 0:return [] if f == 1:return [nameList] permList = [] for i in range(f):newList = nameList[i]remaining = nameList[:i] + nameList[i+1:]for p in createPermutationsList(remaining):permList.append([newList] + p)…arrow_forwardsolve q5 only pleasearrow_forwardGiven a string str and number n, write a program in JavaScript that recursively appends a copy of string str n times and returns the resulting string.arrow_forward
- Write a program that uses a recursive call to find the integer logb of a number. Where logb returns the integer log of a number in a designated base. For example, the integer base 10 log of 1234 is 3, and the integer base 2 log of 1234 is 10. This is a relatively easy calculation. You simply repeatedly divide the number by the base using integer division until the quotient is less than the base and count the number of completed divisions. 1234/10=123 (1) 123/10 12 (2) 12/10 = 1 (3) 1234/2= 617 (1) 617/2 = 308 (2) 308/2 = 154 (3) 154/2 = 77 (4) 77/2 = 38 (5) 38/2 = 19 (6) 19/2 = 9 (7) 9/2=4 (8) 4/2=2(9) 2/2 = 1 (10)arrow_forwardGiven a list of integers, you want to know whether it is possible to divide the integers into two sets, so that the sums of the two sets are the same. Every integer must be in one set or the other. Write a recursive helper method that takes any number of arguments you like, and make the initial call to your recursive helper method from equalSum(). Do not use any loops or regular expressions. Test case 1: equalSum([2, 3, 5]) true Test case 2: equalSum([2, 2, 5]) falsearrow_forwardIn Java - Implementing Recursion to Provide a Product Using recursion, create a program that will allow a user to enter five numbers. The program will provide the product of all five numbers using recursive methods.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education