Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java or Python programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
The code you provided is almost correct ! public static void sortArray(int[] array) { int temp; for (int i = 0; i < array.length - 1; i++) { for (int j = i + 1; j < array.length; j++) { if (array[i] > array[j]) { temp = array[i]; array[i] = array[j]; array[j] = temp; } } } }
Guys if you want to do it without so much trouble you can either use Arrays.sort()-->it arrange the array in ascending order Ex: int[] arr ={22,11,33,1}; Arrays.sort(arr); System.out.println(Arrays.toString(arr); Output-->[1,11,22,33] Or else you can just write the code given in the video it will help you as u might have to arrange the array in the descending order.
My pleasure dude .. Happy learning ! If you wish to have one to one java classes any time in your career .. Don't forget to contact us at dreamdot1709@gmail.com
Bro ur video very useful,pls upload video for Ques is:merge two arrays and sort the array in ascending and remove the duplicate elements from the array in one program A[ ]={2,3,1,4,5,6,7};B[ ]={7,10,8,6,8,6,9}
@@Raven-ql3im j = j+1 starts comparing i with the next element directly and what j=1 does is that it makes it first compare i to itself then move on to the next element. Both cases work since our condition is > and not >=
Concept is to compare each element of the array with all other elements and swap them if it is greater or smaller based on the order .. if we continue doing it .. at the end you ll get sorted array .. check the video as I have step by step explanation .. please write to us for any further questions
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
What id love to know is why do people refer to using the merge sort algorithm when something like this is so much simpler and less coding overall. What’s so special about merge sort???
It could be the execution time .. normally when choosing an algorithm for sorting we should rely on efficiency . May be you can compare the time difference between these 2 algos ..
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
bro can we use Arrays class methods for solving such questions in interview? As Arrays class has direct sort method. And can we use collections for solving interview questions?
Hi .. we shouldn't use inbuilt functions for solving such problems .. companies will try to test your logical thinking in programs .. so always write your logic and avoid using inbuilt functions
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java or Python programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
Hi, are you still doing this?
The code you provided is almost correct !
public static void sortArray(int[] array) {
int temp;
for (int i = 0; i < array.length - 1; i++) {
for (int j = i + 1; j < array.length; j++) {
if (array[i] > array[j]) {
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
}
so to call that method do i just write this
sortArray(v)
v is an array and do I need to put it in a for loop or just like that?
Guys if you want to do it without so much trouble you can either use Arrays.sort()-->it arrange the array in ascending order
Ex:
int[] arr ={22,11,33,1};
Arrays.sort(arr);
System.out.println(Arrays.toString(arr);
Output-->[1,11,22,33]
Or else you can just write the code given in the video it will help you as u might have to arrange the array in the descending order.
Looked so long for how to sort in descending order, you saved me, thanks sir!!
My pleasure dude .. Happy learning ! If you wish to have one to one java classes any time in your career .. Don't forget to contact us at dreamdot1709@gmail.com
Bro ur video very useful,pls upload video for
Ques is:merge two arrays and sort the array in ascending and remove the duplicate elements from the array in one program
A[ ]={2,3,1,4,5,6,7};B[ ]={7,10,8,6,8,6,9}
can you explain the backend logic for this program?
5:30 must
Thanks sir for made this video.
Our pleasure
thank you. what is the name of this algorithm
great explanation,but why didn't you start j at i+1? considering you are not comparing the first element with itself.
Valid point mate .. we can very well do it ..
That's also my question, I've also seen it but what is the difference between j=i+1 and j=1 ?
@@dreamdot9686 sir I did too..the end test cases are showing time limit exceed when some large arrays are given as input
@@Raven-ql3im j = j+1 starts comparing i with the next element directly and what j=1 does is that it makes it first compare i to itself then move on to the next element. Both cases work since our condition is > and not >=
Because by doing j=i+1 you will not traverse all the elements all the time. So we have to put j=i
tnx way too much helpfull :)
Appreciate your comments
Hi... Can you please explain what you used in for loop to print the sorted array..
Concept is to compare each element of the array with all other elements and swap them if it is greater or smaller based on the order .. if we continue doing it .. at the end you ll get sorted array .. check the video as I have step by step explanation .. please write to us for any further questions
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
thank you sir 😍
Good mornig sir
Thank You sir
Our pleasure
Thanks for this!
Our pleasure !
this was great! Thank You
Thank you
this video is so help ful thank you pro
Our pleasure bro .. Anytime if you wish to have one to one java classes don't hesitate to contact dreamdot1709@gmail.com
5:42
This video was so helpful. Thank you!
Our pleasure.. Anytime if you wish to have one to one java classes don't hesitate to contact dreamdot1709@gmail.com
very helpful
Thanks
Great video! but may I ask if what was the point of this code
temp=num[i];
num[i]=num[j];
num[j]=temp;
This code will swap the values in i'th and j'th position using a temporary variable
What id love to know is why do people refer to using the merge sort algorithm when something like this is so much simpler and less coding overall. What’s so special about merge sort???
It could be the execution time .. normally when choosing an algorithm for sorting we should rely on efficiency . May be you can compare the time difference between these 2 algos ..
Exactly my idea at first to do this but failed then looked it up
Well done
Nice job, the best and the simplest code.
Thanks mate
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
bro can we use Arrays class methods for solving such questions in interview? As Arrays class has direct sort method. And can we use collections for solving interview questions?
Hi .. we shouldn't use inbuilt functions for solving such problems .. companies will try to test your logical thinking in programs .. so always write your logic and avoid using inbuilt functions
I was tasked to fill an array with random numbers and then check if its in increasing order or not how do i simply check for an order? Thanks
To check if the elements are in increasing order .. you can iterate through the array and compare every i th element with i+1 th element..
Is this binary sort?
This is selection sort
Can we give this example in bubble sort??
Yess .. it's selection sort .. if possible ll share video on bubble sort soon
Sir app jis pr coding kr rha ho bo bali link chiya mujhe
take and array from the user and sort it in assending order and then calculate its median and mode
any one solve this rapidly
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
KVM
shouldn't be i+1? otherwise, you are saying 44 > 44?
Yep you can very well do that ... It's a miss from my end
Sir ap program konse software m krte h
You can use any code editor which supports java .. I have used eclipse IDE
👍
😀
font name?
KDE
Which sorting is this
Bubble sort
Hello Guys , We are a team of software professionals working for top MNC's and product companies . If you are interested in having one to one online classes for learning Java programming please reach us at dreamdot1709@gmail.com . Our classes will be completely practical which will help you to crack Interviews and work better in IT industry .
font name?