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



    Count Sort in c++
    
    
    #include < iostream.h >
    #include < stdio.h >
    #include < conio.h >
    
        void print(int a[]) {
      for (int i = 0; i < 10; i++) {
        cout < < a[i] < < "-";
      }
      cout < < endl;
    }
    
    int max(int a[]) {
      int mac = 0;
      for (int i = 0; i < 10; i++) {
        if (a[i] > mac) {
          mac = a[i];
        }
      }
      cout < < "ths is mac " < < mac < < endl;
      return mac;
    }
    
    void countTimes(int a[], int b[]) {
      int maxi = max(a);
    
      for (int i = 0; i < = maxi; i++) {
        b[i] = 0;
    
      }
      for (i = 0; i < 10; i++) {
        b[a[i]] = b[a[i]] + 1;
      }
    }
    
    void countRanks(int b[]) {
      for (int i = 1; i < = 7; i++) {
        b[i] += b[i - 1];
      }
    }
    void countSort(int a[], int b[], int c[]) {
      int l = 0;
      for (int i = 9; i >= 0; i--) {
        cout < < a[i] < < "-" < < b[a[i]] < < "\n";
        c[b[a[i]] - 1] = a[i];
        b[a[i]] = b[a[i]] - 1;
      }
      print(c);
    }
    
    void main() {
      clrscr();
    
      int a[] = {
          1, 2, 4, 6, 7, 7, 0, 6, 3, 5};
      print(a);
      int * b;
      int mac = max(a);
      int c[] = {
          0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
      b = new int[mac];
    
      countTimes(a, b);
      countRanks(b);
      countSort(a, b, c);
      print(c);
    }
    
    request a code or suggestion


    Email:
    Category


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