사용했던 컴파일러 중 어느 것도 디버깅 할 수 없습니다. 나는 목록의 끝에 새 노드를 추가하고 표시하려고하는데, 어떤 종류의 오류도 표시하지 않고 있습니다. 두 가지 모두 Windows에서 오류를 보내지 않습니다. 메모리 누출 일 수 있습니다. 제발 도와주세요Circular SIngly LInked LIst, 새 노드 추가 및 표시
#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();
}
이 키보드에 문제가있을 것 같습니다 begginng에 할 일 {} 동안() 문 및 initilize endptr를 사용할 수 있습니다. – leppie
디스플레이 함수에서 while 루프에서 firstptr 대신 tempptr을 사용하려고합니다. –
"if (firstptr = NULL)"또는 "if (firstptr == NULL)"조건을 확인하십시오. – theharshest