Compare the first and second items

Assignment Help JAVA Programming
Reference no: EM131590927

SORTING:

An array is said to be ordered if its values are either ascending or descending order. In an ascending ordered array, the value of each element is less than or equal to the value of the next element. That is, [each element] <= [next element] .

A sort is an algorithm for ordering an array. Of the many different techniques for sorting an array we disbuss the bubble sort. .

It recwires the swapping of values sorted in a pair of variables. If varl, var2, and temp are all variables of the same type, then the statements
temp =varl
varl=var2
var2=temp

Assign varl's value to var2 and var2's value to varl.

Bubble Sort: The bubble sort is an algorithm that compares adjacent items and swaps those that are out of order. If this process repeated enough times , the list will be ordered.

Let's carry out this process on the list.

The steps for each pass through the list are as follows:

1. Compare the first and second items. If they are out of order, swap them.

2. Compare the second and third item. If they are out of order, swap them.

3.Repeat this pattern for all remaining pairs.

The first time through the list, this process is repeated to the enoreffirelist. This is called first pass. After the first pass the last item will be in its proper position. Therefore, the second pass does not have to consider it and so requires one less comparison. At the end of the second pass, the last two items will be in the proper position. Each successive pass requires one less comparison. After four passes, the last four items will be in their proper positions, and hence, the first will be also.

As a specific example of this process, consider the list of numbers: 21 13 17 5 3

This rocess corn letes the ust a ass through the data and results in the largest number moving to the bottom of the list. As the lamest value sinks to its resting place at the bottom o the list the smaller elements slowl rise or "bubble" to the to' o the list. This bubbling effect of the smaller elements is what Rave rise to the name "bubble" sort for this sorting algorithm.'

Reference no: EM131590927

Questions Cloud

What are the forces driving the initiative : Decide what change management issues are present that limit the organization's efforts in continuous improvement. What are the forces driving the initiative?
Distance from the concave lens : A diverging lens of focal length -9cm is placed 20 cm to the right of the convex lens. Find: (need help with this whole section)
The sociological characteristics of religion in the us : Describe three or four solutions that you would like to present to your local school board to improve the educational system.
What value does open source information have : What value does Open Source information have for law enforcement intelligence
Compare the first and second items : Compare the first and second items. If they are out of order, swap them - Compare the second and third item. If they are out of order, swap them
Analyze the competitive advantage of your selected company : Analyze the competitive advantage of your selected company. Explain the effectiveness of the measurement guidelines your selected company uses.
What is the corresponding distance at apogee : If the distance from the center of the Earth to the satellite at perigee is 2.34 x 10^4 km, what is the corresponding distance at apogee?
Identify at least one law enforcement support group : Identify at least one law enforcement support group and explain their location, services, and what you found most helpful for law enforcement
Relative speed between the rockets : What is the relative speed between the rockets as measured by a passenger on one of them?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Advantages and disadvantages of a stringbuilder

What is the difference between string and StringBuilder? What are the advantages and disadvantages of a StringBuilder

  Java application that asks a user to enter two integers

Write a Java application that asks a user to enter two integers (A and B) and then display the results of A/B. Catch any division by zero errors and prompt the user to reenter the value of B. Be sure your code compiles and runs as expected. Name your..

  What happens if the file test.dat does not exist

What happens if the file test.dat does not exist when you attempt to compile and run the following code?

  Improve the program

Add two telephone handsets to the GUI version of the voice mail program - default close operation but install a WindowListener into the frames

  Question 1a give explanation amp the significance of

question 1a give explanation amp the significance of enterprise java beans ejb in software development.b explain the

  Write java codes to perform sentiment analysis

In this programming assignment, I am asked to write Java codes to perform Sentiment Analysis: classifying movie reviews as positive or negative

  Draw the result of taking the tree in the diagram

Draw the result of taking the tree in the diagram and deleting the root three times using the deletion algorithm from lecture and the web

  What are the main differences between java programming

question 1 what are the major differences between java programming language and any other language? list and discuss

  Given the following data definition classpublic class exam

given the following data definition classpublic class exam private static int totalpublic static void settotalint t

  Write a java program that simulate a number of stopwatches

Write a JAVA program that would simulate a number of stopwatches (e.g. 4 stopwatches) times using the concept of Multithreading. The time of stopwatches increase on their own. Moreover, a stopwatch's time can be increased and decreased using speci..

  Mutator method for every instance variable of a class

Is it required to provide an accessor and/or mutator method for every instance variable of a class? If yes, explain why this is required, and if no, explain why not.

  Advantages of the java object class structure

Discussion Question: What are the advantages of the Java object class structure with its instance fields and methods

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd