Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include //exception is thrown if wrong input class BadInput { public: BadInput (){}; }; template struct Node { E data; Node *next; }; template class

#include  //exception is thrown if wrong input class BadInput { public: BadInput (){}; }; template  struct Node { E data; Node *next; }; template  class SortedChain { public: SortedChain() {first=0;} ~SortedChain(); bool IsEmpty() {return (first==0);} //int Length() const; //bool Search (const K& k, const E& e); SortedChain& Delete(const K& k, E& e); SortedChain& Insert (const K& k,const E& e); void Output() const; private: Node *first; }; template  SortedChain::~SortedChain() { Node *current=first; while (first) { current=first->next; delete first; first=current; } } template  SortedChain& SortedChain::Delete(const K& k, E& e) { Node *prior=first, *current=first; while (current && current->data.Key()  k prior=current; current=current->next; } if (current && current->data.Key() == k) { // e=current->data; if (first == current) //delete first node first=current->next; else prior->next=current->next; delete current; return *this; } else throw BadInput(); } template  SortedChain& SortedChain::Insert(const K& k, const E& e) { Node *prior=first, *current=first; while (current && (current->data).Key() next; } if (current && (current->data).Key() == k) throw BadInput(); //another node with same key else { Node *newp; newp=new Node; if (first == current) { //we like to insert on first position first=newp; } else prior->next=newp; newp->next = current; newp->data=e; return *this; } } template  void SortedChain::Output() const { Node  *current=first; cout data.Key() data.Value() "; current=current->next; } } class TypeE { public: long key; long value; Type(){}; long Key(){return key;} long Value(){return value;} }; main() { try { SortedChain Chain; TypeE e; e.key=2; e.value = 1000; Chain.Insert(e.Key(),e); e.key=4; e.value =500; Chain.Insert(e.Key(),e); e.key=6; e.value =1500; Chain.Insert(e.Key(),e); e.key=1; e.value=3000; Chain.Insert(e.Key(),e); Chain.Output(); Chain.Delete(2,e); Chain.Output(); } catch (BadInput) { cerr  

A dictionary is a list of elements composed of similar data ordered by subset of the data called a "key". For example considerer the following structure for a government database:

struct veterant {

char * Name;

char * Address;

char * City;

char * State;

int Zip[5];

int Social_num [9];

}

Since Social_num uniquely identifies each veterant, is the "key" for which the dictionary is then ordered, that is, for example a key :150453456 comes before key:154567899, since the first social number is less the second one.

image text in transcribed

You must write a function called Merge SortedChain& SortedChain:: Merge (SortedChain & S2 const) { ------- write your function that does the following: Suppose that we declare the following two dictionary objects: main { SortedChain TypeE, long> Chainl; SortedChain TypeE, long> Chain2; Suppose Chainl is : Suppose Chainl is.: 15 | 18 | 19 | 1+ where 5.8.and 9 are the keys, and suppose Chain2 is: 14 7 11107 then Chain1.Merge(Chain2) should be The Merge function will change Chain1, thus you must return a reference to Chain1 that is return(*this). You must write a function called Merge SortedChain& SortedChain:: Merge (SortedChain & S2 const) { ------- write your function that does the following: Suppose that we declare the following two dictionary objects: main { SortedChain TypeE, long> Chainl; SortedChain TypeE, long> Chain2; Suppose Chainl is : Suppose Chainl is.: 15 | 18 | 19 | 1+ where 5.8.and 9 are the keys, and suppose Chain2 is: 14 7 11107 then Chain1.Merge(Chain2) should be The Merge function will change Chain1, thus you must return a reference to Chain1 that is return(*this)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

a. How will the leader be selected?

Answered: 1 week ago

Question

b. Will new members be welcomed?

Answered: 1 week ago