public class Program {
public void start() {
int[] nums = { 35, 90, 5, 45 };
for(int i = nums.length; i > 0; i--){
bubble(nums, i);
}
for (int i = 0; i < nums.length; i++){
System.out.println(nums[i]);
}
}
private void bubble(int[] a, int n){
int temp = 0;
for (int i = 0; i < (n-1); i++) {
if (a[i] > a[i+1]) {
swapElements(a, i, i+1);
}
}
}
private void swapElements(int[] a, int pos1, int pos2){
int temp = a[pos1];
a[pos1] = a[pos2];
a[pos2] = temp;
}
}
I KNOW The answers :) But i want to know how to solve like how does it work through? which steps go first and so forth and so forth? And can you explain whats with the " bubble (nums, i); " and whats its purpose and why is there a method of it " private void bubble(int [ ] a, int n) " Like explain please if you can.
The answers :
5
35
45
90
Like how does it work out in that order?
Please need Help ! :)
Thanks
Copyright © 2024 Q2A.ES - All rights reserved.
Answers & Comments
Verified answer
You seem quite new to Object Oriented Programming.
You must understand the Object Oriented Paradigm to understand your question. For that you need to read some book or go to the internet and search OOP.
Some recommended books according to me are
1. Head First Java - Kathy Sierra and Bert Bates
2.Object Oriented Programming in C++ by E.Balaguruswamy
3.Object Oriented Programming in C++ by Robert Lafore
To just understand Object Oriented Approach to programming you should take a look at Object Oriented Technology by Grady Booch