Question: I need help to Redo the insertion sort algorithm so that the values are inserted into a linked list rather than an array. This eliminates

I need help to Redo the insertion sort algorithm so that the values are inserted into a linked list rather than an array. This eliminates the need to move other values when a new value is inserted, since your algorithm can simply insert a new node where the new value should go. Code your algorithm to produce a complete C++ program that reads in a list of 10 integers, sort the integers, and then writes out the sorted list. Your program should allow the user to repeat the process and sort another list until the user says he or she wants to exit the program. the code is below

#include

#include #define MINIMUM_TABLE_SIZE 10 using namespace std;

enum SourceType {Legal, Vacant, Removed};

struct HashNodeTaken { int entity; enum SourceType data; };

struct HashTable { int size; HashNodeTaken *table; };

int Hashfunction1(int key_value, int size) { return key_value % size; }

int Hashfunction2(int key_value, int size) { return (key_value * size - 1) % size; }

HashTable *startTable(int size) { HashTable *htable; if (size < MINIMUM_TABLE_SIZE) { cout<<"Table Size Too Small.Please Check"<size = size; htable->table = new HashNodeTaken [htable->size]; if (htable->table == NULL) { cout<<"Table Size Too Small.Please Check"<size; i++) { htable->table[i].data = Vacant; htable->table[i].entity = NULL; } return htable; } int Search(int key_value, HashTable *htable) { int hashvalues= Hashfunction1(key_value, htable->size); int size_of_step= Hashfunction2(key_value, htable->size); while (htable->table[hashvalues].data != Vacant && htable->table[hashvalues].entity != key_value) { hashvalues = hashvalues + size_of_step; hashvalues = hashvalues % htable->size; } return hashvalues; } void push(int key_value, HashTable *htable) { int position = Search(key_value, htable); if (htable->table[position].data != Legal ) { htable->table[position].data = Legal; htable->table[position].entity = key_value; } }

HashTable *rehashing(HashTable *htable) { int size = htable->size; HashNodeTaken *table = htable->table; htable = startTable(2 * size); for (int i = 0; i < size; i++) { if (table[i].data == Legal) push(table[i].entity, htable); } free(table); return htable; }

void getdata(HashTable *htable) { for (int i = 0; i < htable->size; i++) { int value = htable->table[i].entity; if (!value) cout<<"position: "<

}

int main() { int value, size, position, i = 1; int select; HashTable *htable; while(1) {

cout<<"Functions in Double Hashing"<>select; switch(select) { case 1: cout<<"Enter size of the Hash Table: "; cin>>size; htable = startTable(size); break; case 2: if (i > htable->size) { cout<<"Table is under overflow rehashing the table"<>value; push(value, htable); i++; break; case 3: getdata(htable); break; case 4: htable = rehashing(htable); break; case 5: exit(1); default: cout<<" Please enter correct option.Check again "; } } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!