Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
int[] array={1,3,2,4};
In this case swap function must return true.
int[] array={2,3,4,1,5}
In this case swap function must return false.
Posted
Comments
Sergey Alexandrovich Kryukov 27-Nov-14 1:23am    
Not clear what you problem is. I feel if you just think at the work "swap" and realize what it should do, you will find out what to do in no time. :-)
—SA
Prakash Dalai 27-Nov-14 1:30am    
I have an integer array. I want to do bubble sort with swap function.If swapping happens once then it will return TRUE or else returns False

Example: int[] arr = new int[4]{1,3,2,4};// Return true because swapping is once
int[] arr1 = new int[4]{2,1,4,3}; //return false because swapping twice
Sergey Alexandrovich Kryukov 27-Nov-14 2:45am    
First, you don't really need it for sorting. Second, nothing prevents you from swapping the way you want and returning whatever you want.
—SA

1 solution

Please see my comment to the question.

Okay, one hint for you: the meaning of the verb "swap" does not imply any result, any status of the operation. Therefore, the function result should be void. Yes, such functions really can be used for bubble sort. This is one of the possible examples from MSDN: http://msdn.microsoft.com/en-us/library/twcad0zb.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900