Linear table Implementations of C + + dictionaries.

Source: Internet
Author: User

#include <iostream> #include <assert.h>using namespace std;struct schoolno{int no;friend bool operator = = ( Const Schoolno &school1,const Schoolno &school2) {return (school1.no==school2.no);} Friend Ostream & operator << (ostream &_o,const schoolno &school) {_o<<school.no;return _o;} friend BOOL operator < (const Schoolno &school1,const schoolno &school2) {return school1.no<school2.no;} friend bool operator > (const schoolno &school1,const schoolno &school2) {return school1.no>school2.no;} friend bool operator <= (const Schoolno &school1,const schoolno &school2) {return school1.no<=school2.no;} friend bool operator >= (const Schoolno &school1,const schoolno &school2) {return school1.no>=school2.no;} friend bool Operator! = (const Schoolno &school1,const schoolno &school2) {return school1.no!=school2.no;}}; struct Information{friend ostream & operator<< (ostream &_o,const Information&_i) {_o<< "\ t" <<_I.age<< "\ T" <<_i.name<<endl;return _o;} int Age;char name[13];}; Template<typename k,typename e>class sortedchain;template<typename k,typename E>class ChainNode{friend Class sortedchain<k,e>;p Ublic:chainnode (): Next (null) {}chainnode (k k,e E): Key (k), Data (E), next (null) {}friend Ostream &operator<< (ostream &_o,const chainnode<k,e> &node) {_o<<node.key<< Node.data;return _o;} Private:e data; K key; Chainnode *next;}; Template<typename k,typename e>class Sortedchain{public:sortedchain () {first = new chainnode<k,e> (); ASSERT (First!=null);}  ~sortedchain () {delete []first; First=null;} Public:chainnode<k,e> &search (const K key) const//search. {chainnode<k,e> *p = First;while (p!=null) {if (P->key==key) Break;p=p->next;} return *p;} void Insert (const K key,e &e) {chainnode<k,e> *node = new chainnode<k,e> (); Node->data=e;node->key =key;node->next=null; chainnode<k,e> *p = First;  while (p->next!=null&& P->next->key<key)//overload {P=p->next;} Node->next = P->next;p->next=node;} Friend Ostream & operator<< (ostream &_o,const sortedchain<k,e> &node) {_o<<node.key; return _o;} void view () {chainnode<k,e> *p = first;cout<< "study number" << "T" << "age" << "\ T" << "name" < <endl;while (p->next!=null) {cout <<p->next->key<<p->next->data;p =p->next;}} BOOL Remove (const K key,e &e)//delete. {chainnode<k,e> *p = first;while (p->next!=null && p->next->key!=key) {p = P->next;} chainnode<k,e> *q = P->next;p->next = Q->next;delete q;} Chainnode<k,e> *begin () const//positioning first. {return (first->next);}  Chainnode<k,e> &next (chainnode<k,e> *current) const//Locate the next. {return * (Current->next);} Private:chainnode<k,e> *first;}; int main () {sortedchain<schoolno,information> a;information _i1={100, "the West Asia"};information _i2={10, "nerf"};information _i3={44, "Shining Rate Wolf"}; Schoolno _no1={3}; Schoolno _no2={1}; Schoolno _no3={2};a.insert (_NO1,_I1); A.insert (_NO2,_I2); A.insert (_NO3,_I3); A.view (); A.remove (_No2,_I2); A.view () ; return 0;}

Linear table Implementations of C + + dictionaries.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.