Home>
Segmentation fault: 11 error when trying to create a binary heap in C ++. I did a lot of searching on the web about the binary heap, but it didn't help. I want to find each level. I would like someone to tell me how to solve it.
Error messageSegmentation fault: 11
Applicable source code
C ++
include<iostream>
using namespace std;
struct node {
struct node * parent;// parent
struct node * left;// left child
struct node * right;// right child
int floor;// hierarchy
};
int main () {
node * n;
n->floor = 0;
int i = 0;
while (i<10) {
node * left, * right;
n->left = left;
n->left->floor = n->floor + 1;
n->right = right;
n->right->floor = n->floor + 1;
n = n->left;
i ++;
}
cout<<n->floor<<endl;
cout<<n->left->floor<<endl;
cout<<n->left->->left->floor<<endl;
}
-
Answer # 1
Related articles
- i get an error when i try to compile
- java - i get an error when i run tomcat and i don't know what to do
- ruby - i get an error when i run rails db: seed
- python - i get an error when i do driverget () in a for loop
- ruby on rails - i get an error when i log in
- i get an error when packaging ue4
- i get an error with c ++ opencv
- python - i get an ssl error when pip install
- c ++ - i get a syntax error
- linux - i get an error when vagrant up
- python - i get a 500 error when outputting csv
- i get an error when i use typescript map
- i get an error when i compile
- url:i get an error when i put the url on tex,
- macos (osx) - i get an error when i open the terminal
- c ++ - error: expected unqualified-id before ‘this’
- when i run java on atom, i get "could not find and load main class xx"
- c ++ - c language: please tell me how to deal with the error message "bus error"!
- c ++ - error in loaddivgraph function
- python 3x - i can't get a discordpy error
Related questions
- resolution of unknown type name'a', which is a c ++ error
- c ++ - libpng build method
- c ++ - forward declaration compilation error for c structs
- about embedding random numbers in c ++ output file names
- c ++ - stack overflow in a dynamic multidimensional array
- c ++ - about getting the number of elements in a two-dimensional array
- c ++ - inside the x and y array
- c # - i want to create software that manages products on ec sites with macros
- visualstudio c ++ linux "undefined reference to pthread_create"
- c ++ - atcoder beginner contest 095 half and half
Declaring a pointer variable does not secure node.
Let's secure node with new node.
Actually, it is better to initialize all of parent, left, and right when new is executed.