Can someone help me on this problem files must be maincpp di

Can someone help me on this problem, files must be main.cpp, dictionary.h , dictionary.cpp, DictEntry.h and DictEntry.cpp ?

This will help you visualize that a Doubly Linked List might on average cut your search time in half by sorting the data, then choosing which end to start the search.

When complete print out each word with spaces in between in a file called revsorted.txt. Start at the back of the list so you end up with a reverse sorted list (words starting with z\'s first).

Some Important tips (please read):
http://www.cplusplus.com/reference/list/list/ (Links to an external site.)

- Remember like a vector, you have a list of a particular type (dictionary in this case)

- A list<dictionary>::iterator is a pointer to a list containing dictionary items. Not every operator is defined, but ++ and -- are defined, so you can increment or decrement the pointer.

- There are member functions for a list .begin() which is pointing to the first item on the list and .end() which is the last pointer NULL. So, you generally want to loop from .begin() to != .end()

To start at the back (tail pointer) and work you way to the front you want to reverse the process. so instead of an iterator (which points to the head of the list), you want to use reverse_iterator. And instead of .begin() to != .end(), you want to go from .rbegin() to != .rend()

In order to use the .sort() function for lists, you must overload the operator <, as a friend function of the class. The .sort() function uses this operator to sort.

Remember if you are looking at the VALUE of what the pointer points to, you must dereference the pointer. An iterator or reverse_iterator is a pointer. If you are pointing to a class with a public member function called findValue, you would write that as xPtr->getWords(), NOT xPtr.findValue.

Solution

#include<iostream>

#include<conio.h>

#include<stdlib.h>

using namespace std;

# define max 10

typedef struct list

{

int data;

struct list *next;

}node_type;

node_type *ptr[max],*root[max],*temp[max];

class Dictionary

{

public:

int index;

Dictionary();

void insert(int);

void search(int);

void delete_ele(int);

};

Dictionary::Dictionary()

{

index=-1;

for(int i=0;i<max;i++)

{

root[i]=NULL;

ptr[i]=NULL;

temp[i]=NULL;

}

}

void Dictionary::insert(int key)

{

index=int(key%max);

ptr[index]=(node_type*)malloc(sizeof(node_type));

ptr[index]->data=key;

if(root[index]==NULL)

{

root[index]=ptr[index];

root[index]->next=NULL;

temp[index]=ptr[index];

}

else

{

temp[index]=root[index];

while(temp[index]->next!=NULL)

temp[index]=temp[index]->next;

temp[index]->next=ptr[index];

}

}

void Dictionary::search(int key)

{

int flag=0;

index=int(key%max);

temp[index]=root[index];

while(temp[index]!=NULL)

{

if(temp[index]->data==key)

{

cout<<\"\ Search key is found!!\";

flag=1;

break;

}

else temp[index]=temp[index]->next;

}

if (flag==0)

cout<<\"\ search key not found.......\";

}

void Dictionary::delete_ele(int key)

{

index=int(key%max);

temp[index]=root[index];

while(temp[index]->data!=key && temp[index]!=NULL)

{

ptr[index]=temp[index];

temp[index]=temp[index]->next;

}

ptr[index]->next=temp[index]->next;

cout<<\"\ \"<<temp[index]->data<<\" has been deleted.\";

temp[index]->data=-1;

temp[index]=NULL;

free(temp[index]);

}

main()

{

int val,ch,n,num;

char c;

Dictionary d;

do

{

cout<<\"\ MENU:\ 1.Create\";

cout<<\"\ 2.Search for a value\ 3.Delete an value\";

cout<<\"\ Enter your choice:\";

cin>>ch;

switch(ch)

{

case 1:cout<<\"\ Enter the number of elements to be inserted:\";

       cin>>n;

       cout<<\"\ Enter the elements to be inserted:\";

     for(int i=0;i<n;i++)

       {

       cin>>num;

       d.insert(num);

       }

       break;

case 2:cout<<\"\ Enter the element to be searched:\";

       cin>>n;

       d.search(n);

case 3:cout<<\"\ Enter the element to be deleted:\";

       cin>>n;

      d.delete_ele(n);

       break;

default:cout<<\"\ Invalid choice....\";

}

cout<<\"\ Enter y to continue......\";

cin>>c;

}while(c==\'y\');

getch();

}

Can someone help me on this problem, files must be main.cpp, dictionary.h , dictionary.cpp, DictEntry.h and DictEntry.cpp ? This will help you visualize that a
Can someone help me on this problem, files must be main.cpp, dictionary.h , dictionary.cpp, DictEntry.h and DictEntry.cpp ? This will help you visualize that a
Can someone help me on this problem, files must be main.cpp, dictionary.h , dictionary.cpp, DictEntry.h and DictEntry.cpp ? This will help you visualize that a
Can someone help me on this problem, files must be main.cpp, dictionary.h , dictionary.cpp, DictEntry.h and DictEntry.cpp ? This will help you visualize that a
Can someone help me on this problem, files must be main.cpp, dictionary.h , dictionary.cpp, DictEntry.h and DictEntry.cpp ? This will help you visualize that a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site