Thread: Sort array using 2 thread

  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    15

    Sort array using 2 thread

    hi all i need ur help in how i can .....

    sort array using ,,,, 2 threads...


    here is my coad


    Code:
    public class Sort {      public static void main(String[] args) {      
                int[] array = {3, 4, 12, 6, 7, 2, 3, 23, 1, 0, -9};             
         int i;                                               
    for (i=0;i<array.length;++i) {           
      System.out.print(" " + array[i]);                      }             
        System.out.println("");        
      int[] result = new int[array.length];     
    
         
    // what i have to do here                
    
      for (i=0;i<result.length;++i) {          
       System.out.print(" " + result[i]);             
             }               
       System.out.println("");      }
     }

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Hmm...
    Posting in the wrong forum - tick. (This is Java? code I think, certainly not C!)
    Bad spelling - tick.
    Bad punctuation - tick.
    Complete and utter lack of capitalisation - tick.
    Horrible code formatting - tick.
    Trying to solve a ridiculous problem - tick. (It would probably take more time to start a second thread than to just sort 11 numbers in one thread)

    Am I going to just move right along and ignore this thread? - one big fat tick!
    Last edited by iMalc; 04-23-2012 at 01:24 AM.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    15
    How i write Java application that sorts an array of integers using two threads. The rst thread
    sorts the rst half of the array, the second the second half. Both threads should run in parallel.
    After the threads have nished their work, the two halves must be merged into one sorted
    array.

    Code:
    public class Sort {     
     public static void main(String[] args) {      
         int[] array = {3, 4, 12, 6, 7, 2, 3, 23, 1, 0, -9};             
         int i;                                               
    for (i=0;i<array.length;++i) {           
      System.out.print(" " + array[i]);   
        }             
        
    System.out.println("");        
      int[] result = new int[array.length];     
     
          
    // what i have to do here                
     
      for (i=0;i<result.length;++i) {          
       System.out.print(" " + result[i]);             
             }               
    
       System.out.println("");      }
    
     }

  4. #4
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Are you deaf???? This is the C Forum, nobody cares about your Java rubbish
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Moved to Tech Board.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Dec 2011
    Posts
    795
    The whole basis of this thread is dumb. Why would you need threads to sort an array of integers? Even in a suitably sized array, the work needed to start/stop/communicate between the threads, would be more than using only one.

    hi all i need ur help in how i can .....

    sort array using ,,,, 2 threads...


    here is my coad
    You sound illiterate. May I recommend any of these sites:
    > Guide to Grammar and Writing
    > Capitalization | Punctuation Rules
    > Dictionary.com | Find the Meanings and Definitions of Words at Dictionary.com

  7. #7
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    What is a coad... How do i writ coad D: halp.
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    10 integers is all about "proof of concept". No doubt if the OP had posted something like 10M records, some people would be arguing to post a simplified problem (no win situation).
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with sort 2D array
    By khoavo123 in forum C Programming
    Replies: 3
    Last Post: 02-07-2012, 10:53 PM
  2. Replies: 1
    Last Post: 01-26-2010, 09:02 AM
  3. Replies: 4
    Last Post: 12-06-2009, 12:27 PM
  4. how to sort through an array
    By philipsan in forum C Programming
    Replies: 3
    Last Post: 02-07-2006, 04:04 AM
  5. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 08:05 PM