#pragma once
#include "node.h"
class list
{
public:
list(void);
void insertatfirst(int);
void insertatlast(int);
void removeF(int &);
void removeL(int &);
bool Emty() const;
void print() const;
~list(void);
private:
//error error C2143: syntax error : missing ';' before '*'
node * First; //error here error C4430: missing type specifier - int assumed.
node * Last; ////error here error C4430: missing type specifier - int assumed.
};
//list.cpp
#include "StdAfx.h"
#include "list.h"
#include "node.h"
using namespace std;
list::list(void)
{
}
list::insertatfirst(int d){
if(First == 0)
First=Last = new node(data,0);
else{
node *tmp= new node(d,0);
tmp->ptr=First;
First=tmp;
}
}
list::insertatlast(int d){
node *tmp = new node(d);
if(Last == 0)
First=Last=tmp;
else{
Last->ptr = tmp;
Last = tmp;
}
}
bool list::removeF(int &d){
if(First==0)
return false;
else{
d = First->data;
node *tmp = First;
First = First->ptr;
delete tmp;
return true;
}
}
bool list::removeL(int &d){
if(Last==0)
return false;
d=Last->data;
if(First==Last){
delete First;
First = Last = 0;
}
else{
node *tmp = First;
while(tmp->ptr != Last)
tmp = tmp->ptr;
Last = tmp;
delete Last->ptr;
return true;
}
}
bool list::Emty() const{
return (First ==0);
}
void list::print()const{
node *tmp=First;
while(tmp != 0){
cout<<tmp->data;
tmp=tmp->ptr;
}
}
list::~list(){
while(removeF(d));
}
//node.h
#pragma once
#include "list.h"
class node
{
friend class list;
public:
private :
node(int = 0,node = 0); //error here fatal error C1202: recursive type or function dependency context too complex
~node(void);
int data;
node *ptr;
};
//node.cpp
#include "StdAfx.h"
#include "node.h"
#include "list.h"
node::node(int u, node * p)
{
data = u;
ptr = p;
}
node::~node(void)
{
}
thank you for your help

New Topic/Question
Reply




MultiQuote




|