Please read the question carefully and program this in C do

Please read the question carefully and program this in C, do not post something programmed in Java, thank you:

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

#include<iostream>

#include<stdlib.h>

using namespace std;

/* This is the List Structure */

typedef struct Node

{

                int data;

                struct Node *link;

}node;

node *head = NULL;//The Head node is used to keep track of linked list

/* Driver functions */

void linkedlistshow();

void swap(node *p1, node*p2);

void SelectionSort(node *head);

void linkedlistscaninit(int data, int position);

/* Main method */

int main()

{

                linkedlistscanit4,1);         //This Insers Element at first position LINKED-LIST = / 4 /

                linkedlistscaninit(2,2);    // Insert Element at second position LINKED-LIST = / 4 2 /

               

                printf(\"\ Before sorting = \");    

                linkedlistshow();

               

                SelectionSort(head);                      // now we will be sorting linked list

                printf(\"\ The list After sorting = \");

                linkedlistshow();             

                return 0;

}

/*The function to to sort the linked list */

void SelectionSort(node *head)

{

                node *start = head;

                node *traverse;

                node *min;

               

                while(start->link)

                {

                                min = start;

                                traverse = start->link;

                               

                                while(traverse)

                                {

                                                /*to Find minimum element from array */

                                                if( min->data > traverse->data )

                                                {

                                                                min = traverse;

                                                }

                                               

                                                traverse = traverse->link;

                                }

                                swap(start,min);                                              // Put minimum element on starting location

                                start = start->link;

                }

}

/* swap data field of linked list */

void swap(node *z1, node*z2)

{

                int temp = z1->data;

                z1->data = z2->data;

                z2->data = temp;

}

/* Function for Inserting nodes at defined position */

void linkedlistscanit(int data, int position)

{

                /* firse we will declare node */

                node *temp = (node*)malloc(sizeof(node));

                temp->data = data;

                temp->link = NULL;

                /* if node insertion at first point */

                if(position==1)

                {

                temp->link = head;

                head = temp;

                return ;

                }

               

                /* Adding & Adjusting node links*/

                node *traverse = head;

                for(int i=0; i<position-2; i++)

                {

                traverse = traverse->link;

                }             

                temp->link = traverse->link;

                traverse->link = temp;  

}

/*This is the ffunction for Printing Linked List */

void linkedlistshow()

{

                node *p = head;

               

                while(p)

                {

                                printf(\" %d\",p->data);

                                p = p->link;

                }

                printf(\" \ \ \");

}

Please read the question carefully and program this in C, do not post something programmed in Java, thank you: There is a lot of sorting algorithms. So far, we
Please read the question carefully and program this in C, do not post something programmed in Java, thank you: There is a lot of sorting algorithms. So far, we
Please read the question carefully and program this in C, do not post something programmed in Java, thank you: There is a lot of sorting algorithms. So far, we
Please read the question carefully and program this in C, do not post something programmed in Java, thank you: There is a lot of sorting algorithms. So far, we

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site