ub in code

This is a discussion on ub in code within the C Programming forums, part of the General Programming Boards category; what dose the up in the array sort mean or do Code: #include <stdlib.h> #include <stdio.h> #define uint32 unsigned int ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    104

    ub in code

    what dose the up in the array sort mean or do
    Code:
      
    #include <stdlib.h> 
    #include <stdio.h>
     
     
    #define uint32 unsigned int
     
    typedef int (*CMPFUN)(int, int);
     
     
     
     
    void ArraySort(int This[], CMPFUN fun_ptr, uint32 ub)
    {
      /* bubble sort */
    
      uint32 indx;
      uint32 indx2;
      int temp;
      int temp2;
      int flipped;
    
      if (ub <= 1)
        return;
    
      indx = 1; 
      do
      {
        flipped = 0;
        for (indx2 = ub - 1; indx2 >= indx; --indx2)
        {
          temp = This[indx2];
          temp2 = This[indx2 - 1];
          if ((*fun_ptr)(temp2, temp) > 0)
          {
            This[indx2 - 1] = temp;
            This[indx2] = temp2;
            flipped = 1;
          }
        }
      } while ((++indx < ub) && flipped);
    }
     
    #define ARRAY_SIZE 14
     
    int my_array[ARRAY_SIZE];
     
    void fill_array()
    {
      int indx;
    
      for (indx=0; indx < ARRAY_SIZE; ++indx)
      {
        my_array[indx] = rand();
      }
      /* my_array[ARRAY_SIZE - 1] = ARRAY_SIZE / 3; */
    }
     
    int cmpfun(int a, int b)
    {
      if (a > b)
        return 1;
      else if (a < b)
        return -1;
      else
        return 0;
    }
     
    int main()
    {
      int indx;
      int indx2;
    
      for (indx2 = 0; indx2 < 80000; ++indx2)
      { 
        fill_array();
        ArraySort(my_array, cmpfun, ARRAY_SIZE);
        for (indx=1; indx < ARRAY_SIZE; ++indx)
        {
          if (my_array[indx - 1] > my_array[indx])
          {
            printf("bad sort\n");
            return(1);
          }
        }
      }
    
      return(0);
    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    The size of the array.

    Hint:
    Code:
    ArraySort(my_array, cmpfun, ARRAY_SIZE);
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21