|
the first file intSLList.h
#ifdef INT_LINKED_LIST
#define INT_LINKED_LIST
class IntNode{
public:
int info;
IntNode *next;
IntNode(int el,IntNode *ptr = 0){
info = el; next = ptr;
}
};
class IntSLList{
public:
IntSLList(){
head = tail = 0;
}
~IntSLList();
int isempty(){
return head == 0;
}
void addToHead(int);
void addToTail(int);
int deleteFromHead();
int deleteFromTail();
void deleteNode(int);
bool is IsInList(int) const;
private:
IntNode *Head,*tail;
};
#endif
The second file intSLList.cpp
#include <iostream>
#include "intSLList.h"
using namespace std;
IntSLList::~IntSLList(){
for(IntNode *p;!isempty();){
p = head -> next;
delete head;
head = p;
}
}
void IntSLList::addToHead(int el){
head = new IntNode(el,head);
if (tail == 0)
tail = head;
}
void IntSSList::addToTail(int el){
if (tail != 0){
tail -> next = new IntNode(el);
tail = tail -> next;
}
else{
head = tail = new IntNode(el);
}
}
int IntSLList::deleteFromHead(){
int el = head -> info;
IntNode *tmp = head;
if (head == tail)
head = tail = 0;
else head = head -> next;
delete tmp;
return el;
}
int IntSLList::deleteFromTail(){
int el = tail -> info;
if (head == tail){
delete head;
head = tail = 0;
}
else{
IntNode *tmp;
for (tmp = head;tmp -> next != tail;tmp = tmp -> next)
delete tail;
tail = tmp;
tail -> next = 0;
}
return el;
}
void IntSLList::deleteNode(int el){
if (head != 0){
if (head == tail && el == head->info){
delete head;
head = tail = 0;
}
else if (el == head -> info){
IntNode *tmp = head -> next;
head = head -> next;
delete tmp;
}
else{
IntNode *pred,*tmp;
for (pred = head;tmp = head->next; tmp != 0,&&(tmp->info == el);
pred = pred -> next,tmp = tmp -> next){
if (tmp != 0)
pred -> next = tmp -> next;
if (tmp == tail)
tail = pred;
delete tmp;
}
}
}
}
}
bool IntSLList::isIntLList(int el) const{
IntNode *tmp;
for (tmp = head;tmp != 0&& !(tmp -> info == el);tmp = tmp -> next)
;
return tmp != 0;
}
the bad information:
magicboy@MagicHackComputer lianbiao]$ g++ intSLList.cpp intSLList.h -o lianbiao
intSLList.cpp:6: syntax error before `::' token
intSLList.cpp:10: ISO C++ forbids declaration of `head' with no type
intSLList.cpp:10: `p' was not declared in this scope
intSLList.cpp:11: parse error before `}' token
intSLList.cpp:13: syntax error before `::' token
intSLList.cpp:19: syntax error before `::' token
intSLList.cpp:22: ISO C++ forbids declaration of `tail' with no type
intSLList.cpp:22: base operand of `->' is not a pointer
intSLList.cpp:23: parse error before `}' token
intSLList.cpp:29: syntax error before `::' token
intSLList.cpp:31: syntax error before `*' token
intSLList.cpp:38: syntax error before `::' token
intSLList.cpp:42: ISO C++ forbids declaration of `head' with no type
intSLList.cpp:42: redefinition of `int head'
intSLList.cpp:10: `int head' previously defined here
intSLList.cpp:43: parse error before `}' token
intSLList.cpp:46: syntax error before `->' token
intSLList.cpp:46: ISO C++ forbids declaration of `tmp' with no type
intSLList.cpp:46: base operand of `->' is not a pointer
intSLList.cpp:46: parse error before `)' token
intSLList.cpp:48: ISO C++ forbids declaration of `tail' with no type
intSLList.cpp:48: redefinition of `int tail'
intSLList.cpp:22: `int tail' previously defined here
intSLList.cpp:49: syntax error before `->' token
intSLList.cpp:53: syntax error before `::' token
intSLList.cpp:57: ISO C++ forbids declaration of `head' with no type
intSLList.cpp:57: redefinition of `int head'
intSLList.cpp:42: `int head' previously defined here
intSLList.cpp:58: parse error before `}' token
intSLList.cpp:61: ISO C++ forbids declaration of `head' with no type
intSLList.cpp:61: redefinition of `int head'
intSLList.cpp:57: `int head' previously defined here
intSLList.cpp:61: base operand of `->' is not a pointer
intSLList.cpp:62: parse error before `delete'
intSLList.cpp:66: ISO C++ forbids declaration of `tmp' with no type
intSLList.cpp:66: redefinition of `int tmp'
intSLList.cpp:46: `int tmp' previously defined here
intSLList.cpp:66: base operand of `->' is not a pointer
intSLList.cpp:66: syntax error before `!=' token
intSLList.cpp:67: ISO C++ forbids declaration of `pred' with no type
intSLList.cpp:67: base operand of `->' is not a pointer
intSLList.cpp:67: ISO C++ forbids declaration of `tmp' with no type
intSLList.cpp:67: redefinition of `int tmp'
intSLList.cpp:66: `int tmp' previously defined here
intSLList.cpp:67: base operand of `->' is not a pointer
intSLList.cpp:67: parse error before `)' token
intSLList.cpp:79: syntax error before `::' token
intSLList.cpp:81: syntax error before `!=' token
intSLList.cpp:81: ISO C++ forbids declaration of `tmp' with no type
intSLList.cpp:81: redefinition of `int tmp'
intSLList.cpp:67: `int tmp' previously defined here
intSLList.cpp:81: base operand of `->' is not a pointer
intSLList.cpp:81: parse error before `)' token
g++: compilation of header file requested
why???
IntSLList::~IntSLList() is error!!!why not??? :-) :-) :-) :-) |
|