Hey guys i am in trouble about BST Tree exercise.. i need to create an array that can take number of elements user want and the user has to enter integers but the program need to get this number in one line ... Here is code that i already wrote ;

#include<iostream>
#include<string>
using namespace std;
int main(){
    int size,snumb;
    cin>>size;
    string *myArray = new string[size];
    for(int i=1;i<=size;i++){
            getline (cin,myArray[i]);

            }
            cin>>snumb;
            system("pause");


}

Recommended Answers

All 2 Replies

If the user has to enter integers why are you using a std::string array? Why not an int array?

The loop on line 8 is incorrect. Arrays are always numbered from 0 to the number of elements, for example if the array has 5 elelements then they are numbered 0, 1, 2, 3 and 4. There is no element #5. Your loop should look like this:

for(int i=0;i<size;i++){

Actually the problem is about BST Tree Implement so i guess i need to use char array yes it cant be string .. Here is the problem ;

Input

The program input is 3 lines. In the first line there is an integer denoting the number of integers to put in the tree. In the second line there are these integers. In the third line there is a number to search.

Output

The program output is composed of letters P, L and it is ended by the digit 0 or 1. The letter P means that during the search the program went right, L - left. Digit 1 means, that the number was found, 0 - that it was not

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.