This project will allow you to compare & contrast different 4 sorting techniques, the last of which will be up to you to select.  You will implement the following: Bubble Sort (pair-wise) Bubble Sort (list-wise) [This is the selection sort] Merge Sort Your choice (candidates are the heap, quick, shell, cocktail, bucket, or radix sorts) [These will require independent research)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I need help with doing this in java.

This project will allow you to compare & contrast different 4 sorting techniques, the last of which will be up to you to select.  You will implement the following:

  • Bubble Sort (pair-wise)
  • Bubble Sort (list-wise) [This is the selection sort]
  • Merge Sort
  • Your choice (candidates are the heap, quick, shell, cocktail, bucket, or radix sorts) [These will require independent research)

This project will allow you to compare & contrast different 4 sorting techniques, the last of which will be up to you to select.  You will implement the following:

  • Bubble Sort (pair-wise)
  • Bubble Sort (list-wise) [This is the selection sort]
  • Merge Sort
  • Your choice (candidates are the heap, quick, shell, cocktail, bucket, or radix sorts) [These will require independent research)

 

Expert Solution
Step 1

CompSorting .java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class CompSorting {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner sc=new Scanner(new File("inp.txt"));
        String[] names=new String[600];
        String[] names1=new String[600];
    
        String[] names3=new String[600];
        int i=0;
        while(sc.hasNextLine())
        {
            String s=sc.next();
            names[i]=s;
            names1[i]=s;
            names3[i]=s;
            i++;
        }
          String[] names2=new String[i];
          for(int di=0;di<i;di++)
              names2[di]=names[di];
        sc.close();
        sort_bubbleSort(names,i);
        System.out.println("After bubble sort ");
        for(int k=0;k<i;k++)
            System.out.print(names[k]+" ");
        System.out.println();
        System.out.println();
       sort_selectionSort(names1,i);
       System.out.println("After selection sort ");
        for(int k=0;k<i;k++)
            System.out.print(names[k]+" ");
         System.out.println();
        System.out.println();
         System.out.println("After merge sort ");
        for(int k=0;k<i;k++)
            System.out.print(names[k]+" ");
    }
    // Function to perform bubble sort
    public static void sort_bubbleSort(String[] names,int cou)
    {
         for(int k=0;k<cou;k++)
   // For each pass
   for (int di = 0; di < cou-1; di++)
       for (int dj = 0; dj < cou-di-1; dj++)
           // Swap if the names care out of order
           if (names[dj+1].compareTo(names[dj])<0)
           {
               String tem = names[dj];
               names[dj] = names[dj+1];
               names[dj+1] = tem;
           }
    }
public static void sort_selectionSort(String[] names1,int cou)
{
    for (int di = 0; di < cou- 1; ++di)
    {
      int index_min = di;
      for (int dj = di + 1; dj < cou; ++dj)
      {
        if (names1[dj].compareTo(names1[index_min]) < 0)
        {
          index_min = dj;
        }
      }
      String tem = names1[di];
      names1[di] = names1[index_min];
      names1[index_min] = tem;
    }
}
public static void sort_mergeSort(String[] names2) {
        if (names2.length >= 2) {
            String[] lef = new String[names2.length / 2];
            String[] ri = new String[names2.length - names2.length/ 2];

            for (int di = 0; di < lef.length; di++) {
                lef[di] = names2[di];
            }

            for (int di = 0; di < ri.length; di++) {
                ri[di] = names2[di + names2.length / 2];
            }

            sort_mergeSort(lef);
            sort_mergeSort(ri);
            sort_merge(names2, lef, ri);
        }
    }

public static void sort_merge(String[] names2, String[] lef, String[] ri) {
     int da = 0;
     int db = 0;
     for (int di = 0; di < names2.length; di++) {
        if (db >= ri.length || (da < lef.length && lef[da].compareToIgnoreCase(ri[db]) < 0)) {
            names2[di] = lef[da];
            da++;
        } else {
             names2[di] = ri[db];
             db++;
            }
        }
}
}

 

 

 

inp.txt

abc
bca
cba
qwe
ewq
wqe
tyu
oiu
jkh
fds

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY