Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 16 of 16

Thread: What is the invarient of this code

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What is the invarient of this code

    i made this code but i'm stuck in :
    the fundamental operation in the described algorithm? How many operations does it take?

    What is the invariant of this sorting algorithm?
    the code :
    public class Ass {
     
    public static void swap(int [] x) {
    		int i = 0 ;
    	while (i<x.length){
     
    	for (int j = 0 ; j<x.length ; j++){
    		int b = 0 ;
    		if ( x[j] > x[i] ) {
    			b++ ;
    		}
    		if (b!=0) {
    			 int tmp = x[i] ;
    			 x[i]=x[j] ;
    			 x[j]= tmp ;
     
    		}
     
     
     
     
     
    	} 
    		i++ ;
    	}
    }
    public static void main (String [] args) {
    	int [] array = {5,7,3,6,9,4,2} ;
    	swap(array) ;
    	int m = array.length ;
    	for  (int k = 0 ; k<array.length ; k++) 
    System.out.print(array[k] + " ");
    }
    }
    Last edited by helloworld922; October 15th, 2012 at 12:19 PM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 631 Times in 540 Posts

    Default Re: What is the invarient of this code

    That's not how this works. You're going to have to tell us. We won't do your homework for you.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,732
    Thanks
    50
    Thanked 2,237 Times in 2,209 Posts

    Default Re: What is the invarient of this code

    Provide your answer and we'll comment on it as needed.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 827 Times in 770 Posts
    Blog Entries
    5

    Default Re: What is the invarient of this code

    @alloka, please be respectful of other members. I have removed your post which can be construed as offensive (and has been reported as such by other members). Continued postings such as the one deleted above will force further action. If you wish to receive help, I recommend providing as much information as possible regarding your problem - the link in my signature entitled "Getting Help" may help you along these lines.

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is the invarient of this code

    so is this forum supposed for helping people or telling others what to do ?? , i asked for something and someone come and tell me we will not answer your homework , and btw this isn't a homework .

  6. #6
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What is the invarient of this code

    and thankx for helping btw , i will not ask here again , i don't ask so others can keep info from me .

  7. #7
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 827 Times in 770 Posts
    Blog Entries
    5

    Default Re: What is the invarient of this code

    Quote Originally Posted by alloka View Post
    so is this forum supposed for helping people or telling others what to do ?? , i asked for something and someone come and tell me we will not answer your homework , and btw this isn't a homework .
    Getting help is as much (if not more) an effort on your part as it is the effort of contributors (contributors who are unpaid volunteers). Your post asked 3 questions about code. What did you try to answer said questions? What do you think the answers are? Do you understand the definitions being used in the questions? Including this information brews much better discussion, and give you a much higher chance of receiving help. Not including any of this information is suggestive no attempt was made (whether one was made or not), and is suggestive one is trying to get answers to homework (whether or not this is the case). There are hundreds of posts here, each one competing for attention of contributors. Thus providing clear and concise context rather than "here, answer this" rise to the top of posts that get answered faster.