c++ - c++ 中 java 的完整代码

标签 c++

这里是用c++写的java算法和数据结构的完整代码

#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;
}

错误是这个片段

current.display();  does not work  please help

最佳答案

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;
          }   
    }

关于c++ - c++ 中 java 的完整代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3318451/

相关文章:

c++ - 在 Google 的 CTemplate 中循环

C++ 运算符 & 与枚举的计算结果为 false

C++ Windows HTTP

c++ - 在 Qt 中使用 gSOAP

c++ - 具有同名抽象和定义继承函数的多重继承

c++ - 在 CHOLMOD 或 SuiteSparseQR 中创建稀疏矩阵

c++ - C++中的 bool 运算符

c++ - 计数 Solaris 上的函数调用

c++ - 在 Visual Studio 之外启动时程序运行速度较慢

c++ - 为什么 sizeof(intArray)/sizeof(int) 给出不同的值?