私が使用したコンパイラはどちらもデバッグできません。私はリストの最後に新しいノードを追加しようとしていて、それを表示しようとしています..私を助けてください
#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){
cout << " \n \n I am in the insert at back function: ";
Node*newptr;
newptr = new Node;
newptr->data=val;
if(firstptr=NULL)//means list is empty
{
firstptr=newptr;
}else{
lastptr->nextptr=newptr;
}
lastptr=newptr;
lastptr->nextptr=firstptr;
}
void display(){
Node *temptr,*endptr;
temptr = new Node;
endptr = new Node;
temptr=firstptr;
endptr = NULL;
while(temptr!=endptr){
cout << "I am in the display Function: ";
cout << firstptr->data << " ";
firstptr=firstptr->nextptr;
endptr=firstptr;}
delete temptr;
delete endptr;
}
};
int main()
{
CLLIST obj1;
obj1.insert_at_back(26);
obj1.display();
cout << " \n \n Done !";
getch();
}