C++
-
노드에 값이 있는데도 null입니까?카테고리 없음 2020. 8. 13. 21:43
질문 정수 배열을 기반으로 이진 검색 트리를 만들려고합니다. 배열과 크기를 매개 변수로 취하는 함수 BST를 만들었습니다. 이제 루트 노드와 해당 값을 사용하는 배열의 모든 항목에서 다른 함수 makeBST를 호출합니다. 다른 노드를 생성하고 값에 따라 루트 노드에 연결합니다. 하지만 makeBST 함수는 루트 노드가 null이 아니더라도 자체적으로 반복되지 않고 배열의 모든 값에 대해 NULL 조건을 실행합니다. #include #include using namespace std; class Node { public: int data; Node *left; Node *right; }; Node *newNode(int x){ Node *node = new Node(); node->data = x; nod..
-
파일 C에서 읽는 동안 이상한 문자카테고리 없음 2020. 8. 12. 16:39
질문 inv.txt 파일에서 읽을 때 처음에 이상한 문자가 계속 표시됩니다. 나는 잠시 동안 봤지만 해결책을 찾을 수 없습니다. 아래는 내 코드와 파일의 내용입니다. void installDataToInventory(string fileName) { // Open file to read data std::ifstream myFile; myFile.open(fileName); // Continue if file is open if (myFile.is_open()) { std::string line; // initial count to for putting book info // to approriate slot of inventory array int count = 0; // Loop through the..