using System.IO;
using System;
public class Permutations
{
// Helper method for outputting an array.
private static void PrintArray(string[] array)
{
foreach(string element in array)
{
Console.Write($"{element} ");
}
Console.WriteLine();
}
// Helper method for invoking Generate.
private static void Generate(string[] array)
{
Generate(array.Length,array);
}
private static void Generate(int k, string[] array)
{
if(k==1)
PrintArray(array);
else
{
// Generate permutations for kth unaltered
// Initially k == length(array)
Generate(k-1,array);
// Generate permutations for kth swapped with each k-1
initial
for(int i=0;i<k-1;i++)
{
// Swap choice dependent on parity of k(even or
odd)
if(k%2 == 0)
{
swap(array,i,k-1); // zero indexed , the kth is at k-1
}else
{
swap(array,0,k-1);
}
Generate(k-1,array);
}
}
}
// Helper method to swap the ith and jth index element of
array
private static void swap(string[] array, int i, int j)
{
string temp = array[i];
array[i] = array[j];
array[j] = temp;
}
public static void Main(string[] args)
{
string[] array = {"qaz","wsx","edc"};
Generate(array);
}
}
Output:
C# QUESTION Requirements Your task is to write a program that will print out all the s of the com...
public class Permutations { // Helper method for outputting an array. private static void PrintArray(string[] array) { foreach (string element in array) { Console.Write($"{element} "); } Console.WriteLine(); } // Helper method for invoking Generate. private static void Generate(string[] array) { Generate(array.Length, array); } public static void Main(string[] args) { } } procedure generate(k : integer, A : array of any): if k = 1 then output(A) else // Generate permutations with kth unaltered // Initially k == length(A) generate(k -...
In this assignment, you will write a Java program(s) to print the binary representation of a positive integer inserted from command line. You must finish your assignment in 2 different ways: Using a recursive method Using an iterative method Your main method must be: public static void main(String[] args) { int input; input = Integer.parseInt(args[0]); print_recursion(input); print_binary(input); } You must implement a class and test your program by different input values, including 0. Comment your program properly Example of test...
Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations recursively. Specifically, you will write the bodies for the recursive methods of the ArrayRecursion class, available on the class web page. No credit will be given if any changes are made to ArrayRecursion.java, other than completing the method bodies Note that the public methods of ArrayRecursion – contains(), getIndexOfSmallest(), and sort() – cannot be recursive because they have no parameters. Each of these methods...
Prelab Exercises Your task is to write a Java program that will print out the following message (including the row of equal marks): Computer Science, Yes!!!! ========================= An outline of the program is below. Complete it as follows: a. In the documentation at the top, fill in the name of the file the program would be saved in and a brief description of what the program does. b. Add the code for the main method to do the printing. //...
Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....
In this assignment, you sort a list of strings using mergesort and the compareToIgnoreCase method of the String class. The strings are provided as arguments to your main method. In case you haven't yet learned to configure command-line arguments to main in your IDE, now is a good time to learn. Your program should sort the array of strings using mergesort, then print the strings one per line, in order from smallest ("a") to largest ("z"). The name of your...
A test harness program for testing sorting methods is provided with the rest of the textbook program files. It is the file Sorts.java in the ch11 package. The program includes a swap method that is used by all the sorting methods to swap array elements. Describe an approach to modifying the program so that after calling a sorting method the program prints out the number of swaps needed by the sorting method. Implement your approach. Test your new program by...
Part B (BI). Implement a Red-Black tree with only operation Insert(). Your program should read from a file that contain positive integers and should insert those numbers into the RB tree in that order. Note that the input file will only contain distinct integers. Print your tree by level using positive values for Black color and negative values for Red color Do not print out null nodes. Format for a node: <Node_value>, <Parent_value>). For example, the following tree is represented...
When your program is correctly run, it will be provided two strings: the encrypted message and a string that is in the deciphered text. If fewer/more arguments are provided, your program is to output an error:$ java edu.wit.cs.comp1050.PA4aPlease supply correct inputs: : <encrypted string> <substring>$ java edu.wit.cs.comp1050.PA4a aPlease supply correct inputs: : <encrypted string> <substring>$ java edu.wit.cs.comp1050.PA4a a b cPlease supply correct inputs: : <encrypted string> <substring>If the correct arguments are supplied, you are to output any shifts (00-25) that contain the...
C programming Question1 (a) Write a C program that will print out all command line arguments, in reverse order, one per line. Prefix each line with its index. 6 marks] (b) Consider this C code snippet int a- 100 int b- 42; inte p- &a; int q-b; p qi printf ("%d %d\n" ,a,*p); When this code is executed, what numbers will it print? [2 marks] (c) Consider this C program int main(int argc,char argv) char* target- "Apple" char vord[100] printf...