Why does (start+last)/2 work to calculate the midpoint while start+(last-start)/2 does? To be more specific, I put the contents of a binary tree into an array, sorted it, destroyed the old tree, and plan to rebuild the new one. I know that start+(last-start)/2 as a midpoint calculation works correctly. My problem is that I don't actually know WHY it works. I need to know for a test I have tomorrow. Here's the code for the rebuildTree function. [code] binaryTreeNodePtrType BinaryTree::rebuildTree(int* &a, int start, int last) { binaryTreeNodePtrType ptr = new binaryTreeNodeType; //create new node if (start <= last) { /* …

Member Avatar
Member Avatar
+0 forum 5

I have finished writing my Dynamic, Linked-List implementation of the ADT List, but I can't figure out what the book includes the "void retrieve" function for. Insertion, deletion, the constructors, deconstructors, etc. all have clear purposes, but what is the purpose of the retrieval operation? The header file (class declaration) looks like this: [code] typedef int ListItemType; class List { public: List(); //constructor List(const List& aList); // copy constructor ~List(); //destructor void display(); //output bool isEmpty() const; //checks for empty int getLength() const; void insert_node(int index, const ListItemType& newItem) //inserts node throw (ListIndexOutOfRangeException, ListException); void delete_node(int index) //deletes node throw …

Member Avatar
Member Avatar
+0 forum 3

I searched the forums but I didn't find any useful information. I am just trying to write a simple recursive solution to do F(n). It seems simple to me but I am probably not thinking about it correctly. My program has no errors, but it only returns 55 and then exits. [code]#include <iostream> using namespace std; int F(int); int main() { int fibonacci_input; cout << "Enter a positive integer to be Fibonacci'ed: "; cin >> fibonacci_input; cout << endl << F(fibonacci_input) << endl; return 0; } //end main int F(int n) { if (n == 0) return 0; else if …

Member Avatar
Member Avatar
+0 forum 4

I'm wondering what steps I have to take to make progress in my programming skills. I am just starting my first semester as a computer engineer, and I picked up a lot of the syntax relatively quickly but I still have trouble solving a lot of the problems we get. I am just wondering what kind of ... training? ... I should undergo for myself to make sure by the time I'm out of college I'll have good enough skills in programming (not just C++ of course) that I can start a career for myself. I want to be very …

Member Avatar
Member Avatar
+0 forum 2

The End.