2011-11-21 3 views
-2

내가 skiplist의 구현을 가지고 있지만, 그것은 나에게 매우 분명 오류가 표시skiplist 오류 무엇이 잘못 되었나요?

#include<iostream> 
#include<cstdlib> 
#include<ctime> 
#include<cmath> 
#include<cstring> 
using namespace std; 
const float P=0.5; 
    const int max_level=6; 
template<class T> 
struct Skip 
{ 

    T value; 
    Skip<T> ** forward;//array of pointers 
    Skip(int level,const T &value){ 
     forward=new Skip<T>*[level+1]; 
     memset(forward,0,sizeof(Skip<T>*)*(level+1)); 
     this->value=values; 
    } 


~Skip(){ 

    delete[]forward; 
} 

}; 
template<class T> 

struct skipset 
{ 
    Skip<T>*header; 
    int level; 
    skipset(){ 
header=new Skip<T>(max_level,T()); 
level=0; 
    } 

    ~skipset() 
    { 
     delete header; 

    } 
    void print() const; 
    bool contains(const T &) const; 
    void insert(const T &) ; 
    void delet(const T &); 
    }; 
float frand(){ 
    return (float)rand()/RAND_MAX; 
} 
int random_level(){ 
    static bool first=true; 
    if(first){ 
     srand((unsigned) time(NULL)); 
     first=false; 

    } 
    int lvl=(int)(log(frand())/log(1.-P)); 
    return lvl<max_level?lvl:max_level; 
} 
template<class T> 
void skipset<T>::print()const{ 
    const Skip<T>*x=header->forward[0]; 
    cout<<"{"; 
    while(x!=NULL){ 

     cout<<x->value; 
     x=x->forward[0]; 
     if(x!=NULL) 
      cout<<","; 


    } 
    cout<<"}"<<endl; 
} 

template<class T> 
    bool SkipSet<T>contains(const T &search_value) const { 
    const SkipNode<T> *x = header; 
    for (int i = level; i >= 0; i--) { 
     while (x->forward[i] != NULL && x->forward[i]->value < search_value) { 
      x = x->forward[i]; 
     } 
    } 
    x = x->forward[0]; 

    return x != NULL && x->value == search_value; 


} 
template<class T> 
void skipset<T>::insert(const T &value){ 
    Skip<T> *x=header; 
    Skip<T> *update[max_level+1]; 
    memset(update,0,sizeof(Skip<T>*) * (max_level+1)); 
    for(int i=level;i>=0;i--){ 

     while(x->forward[i]!=NULL && x->forward[i]->value < value) 
      x=x->forward[i]; 


    } 

     update[i]=x; 
     x=x->forward[0]; 
     if(x==NULL || x->value!=value){ 
int lvl=random_level(); 
if(lvl>level){ 
    for(int i=level+1;.i<=lvl;i++){ 
     update[i]=header; 


    } 
    level=lvl; 


} 
x=new Skip<T>(lvl,value); 
for(int i=0;i<=lvl;i++){ 
    x->forward[i]=update[i]->forward[i]; 
    update[i]->forward[i]=x; 



} 



     } 


} 



int main(){ 





    return 0; 
} 

오류가 포함 말한다이다 sring에서 구조의 작동하지, 일부; 미스 등은

1>------ Build started: Project: skip_list, Configuration: Debug Win32 ------ 
1> skip_list.cpp 
1>c:\users\dato\documents\visual studio 2010\projects\skip_list\skip_list\skip_list.cpp(80): error C2143: syntax error : missing ';' before '<' 
1>c:\users\dato\documents\visual studio 2010\projects\skip_list\skip_list\skip_list.cpp(80): error C2988: unrecognizable template declaration/definition 
1>c:\users\dato\documents\visual studio 2010\projects\skip_list\skip_list\skip_list.cpp(80): error C2059: syntax error : '<' 
1>c:\users\dato\documents\visual studio 2010\projects\skip_list\skip_list\skip_list.cpp(80): error C2039: 'contains' : is not a member of '`global namespace'' 
1>c:\users\dato\documents\visual studio 2010\projects\skip_list\skip_list\skip_list.cpp(94): error C2065: 'T' : undeclared identifier 
1>c:\users\dato\documents\visual studio 2010\projects\skip_list\skip_list\skip_list.cpp(94): error C2143: syntax error : missing ';' before '{' 
1>c:\users\dato\documents\visual studio 2010\projects\skip_list\skip_list\skip_list.cpp(94): error C2447: '{' : missing function header (old-style formal list?) 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 
+0

구문 오류를 수정하는 방법은 무엇입니까? ... –

+2

적어도 80 줄을 표시 할 수 있습니까? –

+0

또한 오류가있는 부분을 강조 표시해야합니다. 대부분의 경우 코드를 통해 줄 번호 등을 결정할 시간이 없습니다! – Nim

답변

0

이런 식으로 뭔가해야 코드의 라인 (80)이 없습니다 오류 목록을 참조하십시오 ->

bool SkipSet<T>::contains(const T &search_value) const {... } 

난 당신이 오류가 발생했을 경우 즉 생각합니다. .. (또는 그렇게 생각합니다;))

0

SkipSetskipset이어야합니다.
skipset<T>containsskipset<T>::contains이어야합니다.
SkipNode은 선언되지 않았습니다.

이 시점에서 나는 포기했습니다.