Like Tree1Likes
  • 1 Post By Salem

Converting Java code into C, I need help >.<

This is a discussion on Converting Java code into C, I need help >.< within the C Programming forums, part of the General Programming Boards category; Can someone please convert this Java into C code? I need help >.< Code: static <elem_t extends Comparable <? super ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    9

    Converting Java code into C, I need help >.<

    Can someone please convert this Java into C code? I need help >.<

    Code:
    static <elem_t extends Comparable <? super elem_t>>
    void insertion_sort (elem_t[]array, int nelem) {
                for(int sorted = 1; sorted < nelem; ++sorted) {
                    int slot = sorted;
                    elem_t element = array[slot];
                    for(; slot > 0; --slot) {
                         if (array[slot - 1].compareTo (element) <= 0) break;
                         array[slot] = array[slot - 1];
                    }
                 array[slot] = element;
                 }
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    There are plenty of examples of insertion sort source code on this forum, and on the web.

    Keep searching, I'm sure you'll find something you can copy/paste.
    rags_to_riches likes this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    9
    but, I need the insertion sort to be in this format though >.<

    void inssort (void *base, size_t nelem, size_t size,
    int (*compar) (const void *, const void *));

    The parameters are as follows : base is the base address of the array, nelem is the number of
    elements (length) of the array, size is the number of bytes used by a single array element, and
    compar is a comparison function which produces the usual results, i.e., a negative number if the
    first argument is less than the second, zero if equal, and a positive number of greater.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Yes, the standard template for a sort function written in C.
    Like I said, examples are everywhere - keep looking.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting C code to DLX assembly code
    By xyz3 in forum C Programming
    Replies: 2
    Last Post: 05-17-2010, 02:01 PM
  2. Help Converting Java to C
    By handsomedan in forum C Programming
    Replies: 1
    Last Post: 03-16-2010, 09:17 PM
  3. C Code for converting generic to binary code
    By vanilla in forum C Programming
    Replies: 5
    Last Post: 11-05-2009, 02:34 AM
  4. Replies: 6
    Last Post: 08-07-2003, 02:05 PM
  5. converting from java
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2001, 10:17 AM

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