Total Pageviews

Featured Post

Excel tips and tricks

Things to Remember Borders can be used with the shortcut key Alt + H + B, which will directly take us to the Border option. Giving a border...

Sunday, August 5, 2012

programs

ABC, ACB, BAC, BCA, CAB, CBA.using System;

namespace ConsoleApplication3
{
class Permute
{
private void swap (ref char a, ref char b)
{
if(a==b)return;
a^=b;
b^=a;
a^=b;
}

public void setper(char[] list)
{
int x=list.Length-1;
go(list,0,x);
}

private void go (char[] list, int k, int m)
{
int i;
if (k == m)
{
Console.Write (list);
Console.WriteLine (" ");
}
else
for (i = k; i <= m; i++)
{
swap (ref list[k],ref list[i]);
go (list, k+1, m);
swap (ref list[k],ref list[i]);
}
}
}

class Class1
{
static void Main()
{

Permute p = new Permute();
string c="sagiv";
char []c2=c.ToCharArray ();
/*calling the permute*/
p.setper(c2);
}
}
}You can find above program and algorithm onhttp://efreedom.com/Question/1-756055/Listing-Permutations-String-Integer



binary searc recusion.


using System;


public class BinarySearch {
public static int Search (int[] data, int key, int left, int right) {
if (left <= right) { int middle = (left + right)/2; if (key == data[middle]) return middle; else if (key < data[middle]) return Search(data,key,left,middle-1); else return Search(data,key,middle+1,right); } return -1; } public static void Main(String[] args) { int key; // the search key int index; // the index returned int[] data = new int[10]; for(int i = 0; i < data.Length; i++) data[i] = i; key = 9; index = Search(data, key, 0, data.Length-1); if (index == -1) Console.WriteLine("Key {0} not found", key); else Console.WriteLine ("Key {0} found at index {1}", key, index); } } http://w3mentor.com/learn/asp-dot-net-c-sharp/c-collections-and-generics/examples/recursive-implementation-of-binary-search-in-csharp/ binary serach iteration; http://www.philosophicalgeek.com/category/microsoft/live-search-microsoft/ http://w3mentor.com/learn/category/asp-dot-net-c-sharp/ ================================= Largest sum subarray June 14, 20126 Comments Recursion: M[i] = max sum subarray ending here M[i] = max(M[i-1] + a[i], a[i]) Loved this code #include

#include

using namespace std;

int main() {


int n;

cin >> n;


int max_sum = 0, run_sum = 0;


for (int i = 0, t = -1; i < n; ++i) { cin >> t;


run_sum = max(run_sum + t, t);


max_sum = max(run_sum, max_sum);


}

cout << max_sum << endl;

return 0;


}


-================