24 bytes

  • HOME
  • Algorithms
    blue
  • Bubble Sort
  • Bucket Sort
  • Insertion Sort
  • Selection Sort
  • Merge Sort
  • Quick Sort
  • Heap Sort
  • Counting Sort
  • Stack
  • Queue
  • Double Linked List
  • Binary Search Tree
  • Towers OF Hanoi

  • Java Programs
    green bullet
  • Download RMI Calculator
  • Download file
  • Clock applet
  • File Upload
  • JDOM Parser
  • Client server
  • Udp Client server
  • Sudoku Solver

  • System Programming
  • Newtwork Sniffer
  • Good Links
    green bullet
  • Free Source Code
  • Top Coder
  • Code Project
  • Learn Today
  • Concept
  • Intresting Programs
    green bullet
  • Prime Number
  • GCD Euclids
  • Permutations


  • Google
     
    Web 24bytes.com



    Simple Permutations program in java
    
    
    class permutations {
    
      static void print(int v[], int n) {
        for (int i = 0; i < n; i++) {
          System.out.print(v[i] + " ");
        }
        System.out.println("\n");
      }
    
      static void permute(int v[], int start, int n) {
        if (start == (n - 1)) {                           
    //if its the end of the sequence genereated then print them
          print(v, n);
        }
        else {
          for (int i = start; i < n; i++) { 
    //swap the start element woith the ith element to get n first sequeces
            int temp = v[start];
            v[start] = v[i];
            v[i] = temp;
            permute(v, start + 1, n);
     //of the n the first is kept constant the same is applied for the rest sequence
            v[i] = v[start];
            v[start] = temp;
          }
        }
    
      }
    
      public static void main(String[] args) {
        System.out.println("learn 2day permutaions!");
        int v[] = {
            1, 2, 3};
    //this is the array which should contain the items to be permuted
        permute(v, 0, v.length);
      }
    }
    
     
    
    Simple Permutations program in java
    
    
    request a code or suggestion


    Email:
    Category


    Google
     
    Web 24bytes.com
    . original template by Aran Down.