它只返回一個地址,沒有任何調試錯誤,儘管我的DEV C++和Code :: Blocks編譯器都顯示send不發送窗口錯誤,但它們僅初始化類對象,I已經包括了代碼,誰能告訴我,爲什麼它的發生初學者:圓形單鏈表的第一個程序,
#include <iostream>
#include <conio.h>
using namespace std;
struct Node
{
int data;
Node *nextptr;
};
class CLLIST{
private:
Node*firstptr;
Node*lastptr;
public:
CLLIST(){
cout << "Constructor Called !";
firstptr=lastptr=NULL;
}
void insert_at_back(int val){
if(firstptr==NULL) //it means start of C.LIST
{
Node*temptr = new Node; //means firstptr = temptr
firstptr->data=val;
firstptr=temptr;
firstptr->nextptr=firstptr;
} else{
Node*temp1 = new Node;
Node*temp2 = new Node;
temp1 = firstptr;
while(temp1->nextptr!=firstptr) //traversing
{
temp2 = temp1->nextptr;
temp2->data = val; //inserted at back
temp2->nextptr=firstptr; //circle completed
}
}
}
void printit(){
// functiont o print all the circular link lists data
Node*temp3ptr= new Node;
temp3ptr = firstptr;
while(temp3ptr->nextptr!=firstptr)//traversing
{
cout << temp3ptr->data;
cout << endl;
}
}
};
int main()
{
CLLIST obj1;
obj1.insert_at_back(10);
obj1.insert_at_back(20);
obj1.insert_at_back(30);
obj1.printit();
cout << "Done !";
getch();
}
Node * temptr = new Node; //表示firstptr = temptr firstptr-> data = val; –
firstptr仍然= NULL在那一點 –