GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 07-Apr-2009, 18:37
mterry1 mterry1 is offline
New Member
 
Join Date: Apr 2009
Posts: 1
mterry1 is on a distinguished road

Verify that a binary tree is a binary search tree


I am having trouble with the program I am working on for class. I am trying to verify that a binary tree is a binary search tree using an array implementation, however I am having a problem with the recursion with the function isBST. The code is listed below:

CPP / C++ / C Code:

#include <iostream>
#include <cstddef> // For NULL
#include <string.h>
using namespace std;
const int arraySize = 80; //initilize size of the array

bool isBST(char [], int i);
int main ()
{
	
	char binaryTree[arraySize]; //create array binaryTree
	bool flag = true;
	int i=0;
	cout <<"Please enter a string of characters: " << endl;
	cin.getline(binaryTree, arraySize, '\n');
	for (int i=0; binaryTree[i] !='\n'; i++){//loop to convert lowercase to uppercase characters
		if (binaryTree[i] >=65 && binaryTree[i] <= 90)
			binaryTree[i]+=32;
			cout<< binaryTree[i];//print the uppercase characters
	}
	flag == isBST(binaryTree, i);
	
	if (flag == true)
		//cout << endl << "Yes, it is a binary search tree.";
	else
		cout << endl << "No, it is not a binary search tree.";

	return 0;

}
bool isBST(char binaryTree [], int i)
{
	for (int i=0; i < arraySize-1; i++){
		if(binaryTree[i] < binaryTree [2*i+1]){
			return false;

			if (binaryTree[2*i+2] < binaryTree[i]){
				return false;
			}
		}
		return isBST((binaryTree, 2*i+1) && isBST(binaryTree, 2*i+2));
	}
}

The error I'm getting is: function does not take 1 arguments. The error is pointing to the last return statement.
Last edited by mterry1 : 07-Apr-2009 at 19:15. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 08-Apr-2009, 08:51
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Need Help!!! trouble verifying a binary tree


Quote:
Originally Posted by mterry1
I am having trouble
CPP / C++ / C Code:
		return isBST((binaryTree, 2*i+1) && isBST(binaryTree, 2*i+2));


The error I'm getting is: function does not take 1 arguments...

Look inside the parentheses. Then look (yes, look), at the error message again.

The argument of the function as you have written it is
CPP / C++ / C Code:
(binaryTree, 2*i+1) && isBST(binaryTree, 2*i+2)


Maybe you intended:
CPP / C++ / C Code:
return isBST(binaryTree, 2*i+1) && isBST(binaryTree, 2*i+2);

or, equivalently:
CPP / C++ / C Code:
return (isBST(binaryTree, 2*i+1) && isBST(binaryTree, 2*i+2));
Regards,

Dave
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Link List In C Peter_APIIT C Programming Language 33 12-Jun-2008 14:33
Please Help. I have 3 Qns regarding AVL tree in data structure , Kindly give answer syamsankar C++ Forum 1 30-Mar-2007 09:29
can anyone help me with my tree :) bioeng_mtm C++ Forum 5 22-Apr-2006 13:50
Binary Search Tree in C++ rpg3 C++ Forum 5 02-Apr-2006 10:53
Binary Tree Trouble neufunk C Programming Language 4 06-Dec-2004 10:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:45.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.