2010-07-23 5 views
0

ici est un code complet de l'algorithme et la structure de données en Java écrit en C++code complet de Java en C++

#include <iostream> 
using namespace std; 
class link { 
public: 
    int idata; 
    double ddata; 
    link *next; 
    link (int id,double dd){ 
     idata=id; 
     ddata=dd; 
    } 
public : 
    void display(){ 

     cout<<idata<<"=>"; 
     cout<<ddata; 

    } 

}; 


class linked_list{ 
public : 
    link *first; 

public: 
    linked_list(){ 

     first=NULL; 
    } 
     ~linked_list(){ 

      while (first!=NULL){ 
       link *ptr=first->next; 
       delete first; 
       first=ptr; 
      } 

     } 
public: 
    bool isempthy(){ 
     return (first==NULL); 
    } 
    void insert(int id,double dd){ 


link *newlink= new link(id,dd); 
newlink->next=first; 
first=newlink; 

} 
public: 
    link deletefirst(){ 

     link *temp=first; 
     first=first->next; 
     return *temp; 

    } 

    void displaylist(){ 
     cout<<"List (first-->last"; 

     link *current=first; 

     while (current!=NULL){ 
      current->next; 
      current.display(); 
     } 



    } 






} 



int main(){ 

    linked_list ll; 
    ll.insert(22,12); 
    ll.insert(44,35); 
    ll.insert(12,46); 
    ll.insert(100,23.45); 
    while (!ll.isempthy()){ 
     link alink=ll.deletefirst(); 

     alink.display(); 
    } 


    return 0; 
} 

erreur est que ce fragment

current.display(); does not work please help 
+4

Si vous utilisez C++, peut-être vous devriez obtenir une copie de [algorithmes et structures de données en C++] (http://books.google.co.nz/books?id=R86nZ5b__I0C&printsec=frontcover&dq=algorithms + et + données + structures + in + C% 2B% 2B & source = bl & ots = JHb5a2wqAI & sig = PG4mAXXrxGmBQjTXwlb7GXVkvLQ & hl = fr & ei = YpdJTOPEC5K6sQPIwJxI & sa = X & oi = book_result & ct = résulter & resnum = 2 & ved = 0CB4Q6AEwAQ # v = OnePage & q & f = false). –

+0

cette ligne current-> next; ne fait rien ... – Felics

+1

copie possible de [liste liée de java à C++] (http://stackoverflow.com/questions/3318086/linked-list-from-java-to-c) –

Répondre

1
void displaylist(){ 
     cout<<"List (first-->last"; 

     link *current=first; 

     while (current!=NULL) 
     { 
      //display the current node 
      current->display(); 
      //then move to the next one 
      current = current->next; 
      } 
    } 
1
lien

* Utilisation actuelle current-> au lieu du courant.