// 237陈应扬_实验02.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
template <class Elem> class Link{
public:
Elem element;
Link* next;
Link(Elem& elemval,Link* nextval = NULL){
element = elemval;
next = nextval;
}
Link(Link* nextval = NULL){
next = nextval;
}
};
template <class Elem> class LList:public Link<Elem>{
private:
Link *head;
Link *tail;
Link *fence;
int rightcnt;
int leftcnt;
void init(){
fence = tail = head = 0;
leftcnt = rightcnt = 0;
}
void removeall(){
while(head != NULL){
fence = head;
head = head -> next;
delete fence;
}
}
public:
LList(int size){init();}
~LList(){removeall();}
bool insert(Elem& e){
fence -> next = new Link<Elem>(e,fence -> next);
if(fence = tail)
tail = fence -> next;
rightcnt++;
return true;
}
bool append(Elem& e){
tail = tail -> next =new Link<Elem>(e,NULL);
rightcnt++;
return true;
}
bool remove(Elem& it){
if(fence -> next == NULL)
return false;
it = fence -> next -> element;
Link<Elem>* temp = fence -> next;
fence -> next = temp ->next;
if(temp == tail)
tail = fence;
delete temp;
rightcnt--;
return true;
}
void print(){
Link<Elem>* temp = head;
cout<<"<";
while(temp != fence){
cout<<temp -> next -> element<<" ";
temp = temp -> next;
}
cout<<"|";
while(temp != NULL){
cout<<temp ->next->element<<" ";
temp = temp->next;
}
cout<<">\n";
}
};
int main(int argc, char* argv[])
{
printf("Hello World!\n");
LList <int>list(64);
list.insert(10);
return 0;
}
求解啊,创建的对象调用不了成员函数啊
//
#include "stdafx.h"
#include "iostream"
using namespace std;
template <class Elem> class Link{
public:
Elem element;
Link* next;
Link(Elem& elemval,Link* nextval = NULL){
element = elemval;
next = nextval;
}
Link(Link* nextval = NULL){
next = nextval;
}
};
template <class Elem> class LList:public Link<Elem>{
private:
Link *head;
Link *tail;
Link *fence;
int rightcnt;
int leftcnt;
void init(){
fence = tail = head = 0;
leftcnt = rightcnt = 0;
}
void removeall(){
while(head != NULL){
fence = head;
head = head -> next;
delete fence;
}
}
public:
LList(int size){init();}
~LList(){removeall();}
bool insert(Elem& e){
fence -> next = new Link<Elem>(e,fence -> next);
if(fence = tail)
tail = fence -> next;
rightcnt++;
return true;
}
bool append(Elem& e){
tail = tail -> next =new Link<Elem>(e,NULL);
rightcnt++;
return true;
}
bool remove(Elem& it){
if(fence -> next == NULL)
return false;
it = fence -> next -> element;
Link<Elem>* temp = fence -> next;
fence -> next = temp ->next;
if(temp == tail)
tail = fence;
delete temp;
rightcnt--;
return true;
}
void print(){
Link<Elem>* temp = head;
cout<<"<";
while(temp != fence){
cout<<temp -> next -> element<<" ";
temp = temp -> next;
}
cout<<"|";
while(temp != NULL){
cout<<temp ->next->element<<" ";
temp = temp->next;
}
cout<<">\n";
}
};
int main(int argc, char* argv[])
{
printf("Hello World!\n");
LList <int>list(64);
list.insert(10);
return 0;
}
求解啊,创建的对象调用不了成员函数啊