Program this in C There is a lot of sorting algorithms So fa

Program this in C


There is a lot of sorting algorithms. So far, we have covered selection and insertion sort.
However, we only covered how selection sort is implemented using an array. Every sorting
algorithm implemented using an array can also be implemented using a linked list. In this
assignment, you will implement the selection sort algorithm using a linked list instead of an
array.

You will first create an interface for handling string items. Basically, you will need to do the
following:
• Create an interface named item.h
• Define a type Item represents a char * (i.e., a c-string)
• Implement a less function that compares between two strings and return which one
should precede.


Then, you will add to the linked list interface the following functions:
• linkedlistScanInit:
   • The header of the function will be linkedlistScaninit(pLinkedList list).
   • The function takes a linkedlist as input, reads from the command line a set of strings, and store them inside the linkedlist. You can call the function linkedlistAddNode to add a node to the end of the linked list.
• linkedlistShow:
   • The header of the function will be linkedlistShow(pLinkedList list).
   • The function takes a linkedlist as input, loops through the linkedlist and show what inside it

Finally, you will create a main, your main will be as follow:

//Include the needed headers here
int main(void)
{
pLinkedList list = linkedlistInitDefault();
linkedlistScanInit(list);
linkedlistShow(list);
destroy(&list);
return 0;
}

You will use the code in linkedListSt.h and linkedListSt.c

Solution

import java.util.Collections; import java.util.Comparator; import java.util.LinkedList; public class MyLinkedListSort { public static void main(String a[]){ LinkedList list = new LinkedList(); list.add(new Empl(\"Ram\",3000)); list.add(new Empl(\"John\",6000)); list.add(new Empl(\"Crish\",2000)); list.add(new Empl(\"Tom\",2400)); Collections.sort(list,new MySalaryComp()); System.out.println(\"Sorted list entries: \"); for(Empl e:list){ System.out.println(e); } } } class MySalaryComp implements Comparator{ @Override public int compare(Empl e1, Empl e2) { if(e1.getSalary() < e2.getSalary()){ return 1; } else { return -1; } } } class Empl{ private String name; private int salary; public Empl(String n, int s){ this.name = n; this.salary = s; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } public String toString(){ return \"Name: \"+this.name+\"-- Salary: \"+this.salary; } }
Program this in C There is a lot of sorting algorithms. So far, we have covered selection and insertion sort. However, we only covered how selection sort is imp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site