The array is sorted except the first one

Assignment Help C/C++ Programming
Reference no: EM13168499

the array is sorted except the first one. For example, I have a list{5, 4, 2, 3 ,1}, after sorting the list is {5,1,2,3,4}.

public static void segmentedInsertionSort(AnyType[] list, int n, int h)
    {
       int j;
       System.out.println("hello Nguyen");
       System.out.println("the value of n is " + n + " "+ h);
        AnyType temp;
        for(int i = h; i < n; i++)
        {
            System.out.println("hello Ashley");
            j = i - h;
            while(j >0)
            {
                if (list[j].isBetterThan(list[j + h]))
                {
                    temp = list[j];
                    list[j] = list[j + h];
                    list[j + h] = temp;
                    j = j - h;
                    System.out.println("hello Connie");
                
                }
                else
                {
                    j = 0;
                }
            }
        }
    }
    
   
    
    public static void shellSort(AnyType[] list, int n)
    {
        int h = 1;
        while (h < n/3)
        {
            h = h*3 +1;
        }
        
        while(h > 0)
        {
            segmentedInsertionSort(list, n, h);
            h = (h - 1)/3;
        }
    
    }

 

 

Reference no: EM13168499

Questions Cloud

Modify the program in 6a so that, in addition to the cents : Modify the program in 6a so that, in addition to the cents, the user enters the denomination of the coin to which to convert the pennies, such as 5 for nickles or 25 for quarters.
Which allows to input a year and when hit the check button : Create a JAVA GUI (With Frame), which allows to input a year and when hit the check button, will show the picture of Chinese zodiac animal! I am trying to make a calculator: i have the method for or the calculation method to show how to calculate:
Determine the formula for x : When the compound spontaneously decomposes, the piston moves up, the temperature of the water reaches a maximum of 29.52°C, and then it gradually decreases as the water loses heat to the surrounding air.
How many cro42- ions are present : A sample of silver chromate (Ag2CrO4) has a mass of 24.7 g. (a) How many Ag+ ions are present? ions (b) How many CrO42- ions are present? ions (c) What is the mass in grams of one formula unit of silver chromate? g/formula unit
The array is sorted except the first one : the array is sorted except the first one
Write a lisp program to evaluate lisp arithmetic : Write a Lisp program to evaluate Lisp arithmetic expressions. Assume four operators may be used in expressions and they are +, -, *, and /. All these operators are binary, i.e., they are applied in an expression in this format
Java is considered to be safe from buffer overflows : Java is considered to be safe from buffer overflows. Does that make it more appropriate to use as a s development language when security is concerned? Be sure and weight all if the risks involved in product development, not just the security aspec..
Describe an algorithm that takes as input a list of n : Describe an algorithm that takes as input a list of n distinct integers and finds the location of the largest even integer in the list or returns 0 if there are no even integers in the list.
That reads ten numbers from input and prints : Write a C program that reads ten numbers from input and prints them in reverse order. We assume that the data consists of integers. The program should conform to the following format

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a c++ program to draw the five olympic rings

Write a C++ program to draw the five Olympic rings. Make the circles have a thickness of 5 pixel

  Write a c program to compute dr if f1=50 lb and f2 = 4000

make a program for:A hydraulic lift as shown below from fluid mechanics, it can be shown that a small force F1     acting over a piston of diameter D 1    can be multiplied into a large force   F 2    acting over a piston of diameter D 2  .

  Program to generate a star-based histogram for a quiz

Write a C++ program to generate a star-based histogram for a quiz (maximum score possible is 5) given to a class of N students, where N is an input from the user. Use arrays for computation.

  Program to input the length of the side from the keyboard

write a program to input the length of the side from the keyboard ,use the class to obtain the areas of all shapes and display the results on the screen

  Goto statements to explicitly

Rewrite the following program fragment using goto statements to explicitly show the flow control through the loop.

  Write a program that allows users to enter a dollar amount

Write a program that allows users to enter a dollar amount for their bank account balance at the beginning of the month. Then ask the user to enter a dollar amount for any number of checks written in a month, up to 50. Include an approriate sentinel ..

  Grocery store program

This program draws upon several concepts that were covered in CptS 121 and should serve as a good refresher for CptS 122. Our store, Cougar Mart, maintains its inventory in a text file. Not being very tech savvy, the owner of Cougar Mart needs you to..

  Prompt the user for and read 6 numbers

Write a program using an array that will store input data. Prompt the user for and read 6 numbers between 70 and 90. Verify the numbers should be greater than 70 and less than 90. If the number is less than or equal to 70 or greater than 90, repro..

  Complete the design and implementation

Complete the design and implementation of the class customerType defined in the Programming Example Video Store. b. Design and implement the class customerListType to create and maintain a list of customers for the video store.

  Write a program which accepts the total of food and drink

Write a program which accepts the total of food and drink purchased for a restaurant bill as input. The output should be adjusted bill with a sales tax of six percent 6% and a tip (gratuity) of 15%.

  Write c program to add two integers and prints out average

Write a C program that prompts for a variable number of integers, adds them up, and prints out the average. The user will enter either an integer to be averaged.

  Write a program that reads an array with wind-tunnel test

write a program that reads an array with wind-tunnel test data then allowss the user to enter a flight-path angle. If the angle is within the bounds of the data set, the program should then use linear inteerpolation to compute the corresponding coeff..

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