Salve ragazzi ho la seguente function per inserire un elemento in un bst
Mi dà questi 6 errori:codice:#include <iostream> using namespace std; // Creo il tipo di dato tree typedef struct node { node *left; node *right; int info; } tree; // Prototipi delle functions tree bst_insert(tree root, int elem); int main() { tree *root; int elemento; root=null; do { cout<<"Inserisci l'elemento da inserire:"<<endl; cin>>elemento; bst_insert(root, elemento); cout<<"Vuoi inserire un altro elemento?"; cin>>scelta; } while (scelta == 's' or scelta == 'S'); } /* Inserimento di un elemento nel bst */ tree bst_insert(tree root, int elem) { if ( root == null ) { root = new tree; root.info = elem; root.left = null; root.right = null; } else { if ( elem < root.info ) { root = bst_insert(root.left, elem); } else if ( elem > root.info ) { root = bst_insert(root.right, elem); } else { cout<<"Dato duplicato\n"; } } return (root); }
Qualcuno può aiutarmi?codice:Compiling: C:\Users\Gaten\Desktop\bst.cpp C:\Users\Gaten\Desktop\bst.cpp: In function 'int main()': C:\Users\Gaten\Desktop\bst.cpp:30: error: 'null' was not declared in this scope C:\Users\Gaten\Desktop\bst.cpp:35: error: conversion from 'tree*' to non-scalar type 'tree' requested C:\Users\Gaten\Desktop\bst.cpp: In function 'tree bst_insert(tree, int)': C:\Users\Gaten\Desktop\bst.cpp:85: error: 'null' was not declared in this scope C:\Users\Gaten\Desktop\bst.cpp:87: error: no match for 'operator=' in 'root = (tree*)operator new(12u)' C:\Users\Gaten\Desktop\bst.cpp:8: note: candidates are: node& node::operator=(const node&) C:\Users\Gaten\Desktop\bst.cpp:95: error: conversion from 'node*' to non-scalar type 'tree' requested C:\Users\Gaten\Desktop\bst.cpp:98: error: conversion from 'node*' to non-scalar type 'tree' requested Process terminated with status 1 (0 minutes, 0 seconds) 6 errors, 0 warnings

Rispondi quotando