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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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