static ArrayList Permute(int[] a,int start,int finish)) { if(start!=finsh) Permute(a,start+1,finish) } In this recursive function I need to add the int [] a(array) collection to array list and return the array list how can I do that? (simply how to add values to a array list in a recursive function and the return the array list with all values) like ( arraylist alist =new arraylist(); alist .add(1); alist .add(2); then return alist but this wont work in recursive function like above due each time alist get reinitialized
aynka2000
Posts
-
How to use array list in a recursive function:(pls help) -
Using Array LIstCurrently in my function (static void Permute(int[] a, int start, int finish)) all the values in the permutation are printed recursively in a loop I want to change the program so that my function Permute returns an array list of int [] arrays to the Main function in the program static void Main(String [] args) { int [] a=new int[] {3,4,2}; ArrayList sa= Permute(a,0,a.Length-1);=Pass the Array List Console.ReadLine(); Please help Thankyou
public class PermutationsLex
{[STAThread]
static void Main(String [] args)
{
int [] a=new int[] {3,4,2};ArrayList sa= Permute(a,0,a.Length-1);
Console.ReadLine();
}
static void Permute(int[] a, int start, int finish)
{if (start == finish)
{
for (int i = 0; i <= finish; i++)
{
Console.Write(a[i] + " " );
}
Console.WriteLine("");}
else
{for ( int i = start; i <= finish; i++)
{swap(a,start,i);
Permute(a, start+1, finish);
swap(a,start,i);
}
}
}
public static void swap(int[] a, int i, int j)
{int temp = a[i];
a[i] = a[j];
a[j] = temp;}
-
Using Array LIstI wrote recursive function where i need to pass array of integer and output a collection of arraylist in main Below is how i did but how can i change my program to out put recive a arraylist and print out in main Please help Thankyou public class PermutationsLex { [STAThread] static void Main(String [] args) { int [] a=new int[] {3,4,2}; ArrayList sa= Permute(a,0,a.Length-1); Console.ReadLine(); } static ArrayList Permute(int[] a, int start, int finish) { System.Collections.ArrayList permutationsList= new System.Collections.ArrayList(); if (start == finish) { // for (int i = 0; i <= finish; i++) // { // Console.Write(a[i] + " " ); // } // Console.WriteLine(""); } else { for ( int i = start; i <= finish; i++) { swap(a,start,i); Permute(a, start+1, finish); swap(a,start,i); } } } public static void swap(int[] a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; }
-
Using Binary TreesI tried Using binary tree in c# I just tried the insert,delete and find method using recursion But I'm not sure whether is correct and how to use it in main Can somebody please tell is it correct Thanks for checking below is my coding using System; class Node { public int skey; public Node nleft; public Node nRight; public Node left { get {return nleft; } set {nleft=value; } } public Node right { get {return nRight; } set {nRight=value; } } public int vkey { get {return skey; } set {skey=value; } } } class Tree { private Node root; public Tree() { root = null; } //find Node search_binary_tree(Node node,int key) { if (node==null) return null; // not found if (key < node.vkey) return search_binary_tree(node.left, key); else if (key > node.vkey) return search_binary_tree(node.right, key); else return node; } void InsertNode(Node node,Node newNode ) { if (root == null) { root =newNode; } else if (newNode.vkey <= node.vkey) InsertNode(node.left, newNode); else InsertNode(node.right, newNode); } void DeleteNode(Node node) { Node temp = node; if (node.left == null) { node = node.right; temp=null; } else if (node.right == null) { node = node.left; temp=null; } else { // Node has two children - get max of left subtree temp = node.left; while (temp.right != null) { temp = temp.right; } node.vkey = temp.vkey; DeleteNode(temp); } } void traverse_binary_tree(Node treenode) { if (treenode!=null) { traverse_binary_tree(treenode.left); Console.WriteLine(treenode.vkey); traverse_binary_tree(treenode.right); } } So how can i apply main method for this Please Help:) Ayn
-
Build Comment Web Pages Dialog Box in c#Have anyone no how to use how to use Build Comment Web Pages Dialog Box in c#
-
How to use indexesHow to create indexes in vb.net Pls help I will glad to get a reply Thank You
-
hide a from which is not foucsedat main form when you click a command button another form loads when i select the existing value in the popup form i use .show method at that time i want to close the main form and open the main from with the existing value Please help
-
tabpage seting foucsIn tab control the are 3 tab page when i click a button with is in tabpage 1 i have written(tabpage3.focus) the focus to go to tabpage 3 but its not going what can i do pls help
-
business letter using dot netI need to write a business letter, and I would like to try it use in vb.net> > Are there any style sheets
-
xml format:confused:I need to make a letter template using xml in vb.net eg after creating template when use clicks a button in form template must be loaded there he must able to type anything such as hi as above when you type name it must retrieve in order each customer name and under that must print hi according to requirement changing the font bolding and underline it its urgent please please Thanks please email to aynka2000@yahoo.com
-
xmslt templatesI need to make a letter template using xml in vb.net eg after creating template when use clicks a button in form template must be loaded there he must able to type anything such as hi as above when you type name it must retrieve in order each customer name and under that must print hi according to requirement changing the font bolding and underline it its urgent please please Thanks please email to aynka2000@yahoo.com