Thread: Need help with easy Array and bubble sort code

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    2

    Need help with easy Array and bubble sort code

    Hey guys! I Need some help adding a basic bubble sort to this code so it sorts from small to large.

    I need to add it where it says /* Bubble Sort Code */

    Code:
    Thanks!!
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #define MAX 10
    
    int a[MAX];
    
    int main()
    {
      // seed PRNG
      srand(time(NULL));
    
      int i, t, x, y;
    
      printf("The unsorted array:\n");
      for (i=0; i < MAX; i++)
    {
    a[i] = rand() % 1024; // pick pseudorandom numbers between [0] and [1023]
    printf("%d\n", a[i]);
    }
    
    /* Bubble Sort Code */
    
    return 0;
    }
    
    

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    We won't solve your homework for you.

    Here's the wikipedia article on Bubble-sort:
    Bubble sort - Wikipedia
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    There's no reason your array should be global. You should declare it in main().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with bubble sort 2D array
    By khoavo123 in forum C Programming
    Replies: 6
    Last Post: 02-14-2012, 11:23 PM
  2. Bubble Sort Code :(
    By irishfeeney92 in forum C Programming
    Replies: 22
    Last Post: 05-03-2011, 07:22 AM
  3. Bubble Sort Code Problem...
    By h4rrison.james in forum C Programming
    Replies: 7
    Last Post: 01-22-2009, 07:43 AM
  4. bubble sort with an array
    By commandercool in forum C++ Programming
    Replies: 3
    Last Post: 05-13-2005, 01:29 AM
  5. Problem with Bubble Sort code
    By lisa1234 in forum C++ Programming
    Replies: 7
    Last Post: 01-13-2004, 03:40 PM

Tags for this Thread