我正在尝试打印一个链接列表。程序如下:
#include<iostream>
#include<vector>
using namespace std;
class Link
{
public:
int iData;
double dData;
Link* pNext;
Link(int id,double dd)
{
iData = id;
dData = dd;
}
void displayLink()
{
cout<<"iData = "<<iData<<"\n";
cout<<"dData = "<<dData<<"\n";
}
};
class OrderedList
{
private:
Link* pRoot;
public:
OrderedList()
{
pRoot = NULL;
}
void insert(int id,double dd)
{
Link* newlink = new Link(id,dd);
Link* pCurrent = pRoot;
Link* pPrev = pRoot;
while(pCurrent!=NULL&&pCurrent->iData<=id)
{
pPrev = pCurrent;
pCurrent = pCurrent->pNext;
}
newlink->pNext = pCurrent;
if(pCurrent==NULL)
{
pCurrent = newlink;
}
else
{
pPrev->pNext = newlink;
}
}
Link* search(int val)
{
Link* pCurrent = pRoot;
while(pCurrent!=NULL&&pCurrent->iData<val)
{
pCurrent = pCurrent->pNext;
}
return pCurrent;
}
bool remove(int val)
{
Link* pCurrent = pRoot;
Link* pPrev = pRoot;
while(pCurrent!=NULL&&pCurrent->iData<val)
{
pPrev = pCurrent;
pCurrent = pCurrent->pNext;
}
if(pCurrent==NULL)
return false;
else
{
Link* temp = pCurrent;
pPrev->pNext = pCurrent->pNext;
delete temp;
return true;
}
}
void displayList()
{
Link* pCurrent = pRoot;
while(pCurrent!=NULL)
{
pCurrent->displayLink();
pCurrent = pCurrent->pNext;
}
}
};
OrderedList ol;
ol.insert(10,10.10);
ol.insert(11,11.11);
ol.insert(12,12.12);
ol.insert(13,13.13);
ol.insert(14,14.14);
ol.insert(15,15.15);
ol.insert(16,16.16);
ol.insert(17,17.17);
ol.insert(18,18.18);
ol.insert(19,19.19);
ol.insert(20,20.20);
ol.insert(21,21.21);
ol.insert(22,22.22);
ol.insert(23,23.23);
ol.insert(24,24.24);
ol.insert(25,25.25);
ol.insert(26,26.26);
ol.insert(27,27.27);
ol.insert(28,28.28);
ol.insert(29,29.29);
ol.displayList();
我面临的问题是代码看起来正确并且在纸上运行良好。当我尝试在计算机上运行它时,它编译没有任何错误。但是,在执行它时,不会显示任何输出。甚至没有任何错误。该程序只是执行而不显示任何内容。我无法确定问题所在。我认为代码很好。请帮我解决这个问题。