#include<iostream> #include<algorithm> #include<iomanip> #include<cmath> #include<string.h> #include<stdlib.h> #include<sstream> #include<cmath> using namespace std; /*typedef pair<int, int > p; int cmp(p money, p weight){ return (double)money.first / money.second > (double)weight.first / weight.second; }*/ template<typename T > class node{ public : node(T &node) :data(node), next(NULL){} node *next; T &data; }; template <typename T> class nodeLink{ private: node <T> *begin; node<T> *endl; public: nodeLink(); ~nodeLink(); void add(T &); void remove(T &); void print(); }; template <typename T> nodeLink<T> ::nodeLink(){ begin = end = NULL; } template <typename T> nodeLink<T>::~nodeLink(){ if (begin == NULL)return; node<T> *iptr = begin; node<T> *ipre; while (iptr){ ipre = iptr; iptr = ipre->next; delete ipre; } } template <typename T> void nodeLink<T>::add(T &node){ node<T> *temp = new node<T>(node) if (end){ end->next = temp; temp->next = NULL; end - temp; if (begin == NULL){ begin = temp; } } } template <typename T> void nodeLink<T>::print(){ for (node<T> *iptr = begin; iptr; iptr = iptr->next) cout < iptr->data << " "; cout << endl << endl; } template <typename T> void nodeLink<T>::remove(T &node){ node<T> *temp = NULL; node<T> *pre = NULL; for (node<T> *iptr = begin; iptr; iptr = iptr->next){ if (iptr->data = node){ temp = iptr; break; } pre = iptr; } if (temp == NULL)return; if (pre) pre->next = temp->next; else begin = temp->next; if (temp->next == NULL) end = pre; delete temp; } int main(){ nodeLink<char > letter; char a[26]; for (int i = 1; i < 27; i++){ a[i] = i + 64; letter.add(a[i]); } letter.print(); char del; do{ cout << "oout put what a what you want" << endl; cin >> del; if (del == 'q')break; letter.remove(del); cout << " change have ed" << endl; letter.print(); } while (del != 'q'); return 0; }
Idada
相关分类