Results 1 to 3 of 3
  1. #1
    brendan89 is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default post increment inside a loop?

    So I have the following code I am trying to understand regarding a quicksorting algorithm:

    Java Code:
    int end = array.length-1;
    int start = 0;
    int endOfList = start;
    for(int read = start + 1; read<=end; read++)
    		{
    			if(array[read] < pivotValue)
    			{
    				endOfList++;
    				switch(array, read, endOfList);
    			}
    	        }
    switch(array, start, endOfList);
    Now my question:
    I don't see why we need to call the switch method inside the if...could somebody please explain to me what it does and why it's needed?

    Thanks!

  2. #2
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    3

    Default Re: post increment inside a loop?

    Can you provide the whole code with the main method so I can understand what you are trying to do?

  3. #3
    brendan89 is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: post increment inside a loop?

    Quote Originally Posted by fatabass View Post
    Can you provide the whole code with the main method so I can understand what you are trying to do?
    I figured it out last night :) thanks though. Seems like the endoflist gets incremented whenever there is a lower value than the pivot and not incremented when there isn't. The swap at the end puts the pivot back into its correct place in the array. :D

Similar Threads

  1. OnClick inside a loop
    By sehudson in forum New To Java
    Replies: 9
    Last Post: 05-29-2011, 06:14 AM
  2. if else inside while loop??
    By jonytek in forum New To Java
    Replies: 3
    Last Post: 02-17-2011, 09:28 AM
  3. Loop inside a switch
    By mustachMan in forum New To Java
    Replies: 3
    Last Post: 02-26-2010, 03:25 AM
  4. quick pre/post increment question
    By xtrmi in forum New To Java
    Replies: 4
    Last Post: 02-01-2009, 05:47 PM
  5. Restart a For loop and increment an Int value
    By dcnorman07 in forum New To Java
    Replies: 1
    Last Post: 07-12-2008, 12:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •