#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;
}
1 回答
已采纳
Idada
TA贡献3条经验 获得超0个赞
能否告知这是什么书?
1.
char a[26];
for (int i = 1; i < 27; i++){
a[i] = i + 64;
letter.add(a[i]);
}
a数组一共26个元素,没有a[26]这个东西。
2. class名字全是小写,和你传进的参数同名了,那个node
3. 另外还有书写错误:
第25行
第54行
第71行
等等
- 1 回答
- 1 关注
- 1058 浏览
添加回答
举报
0/150
提交
取消