Thanks for all your help. If was easy to get in running recursively but I am preparing for an interview and was told to practice converting a BST for resurrection to using stacks and queues.

I have been playing around with the logic for hours and still have had no luck. The problem I am having is that after I pop 4 I pop 15 before pushing 9. According to what you showed me I should only pop 15 after I popped all the child nodes for 15. This is where my problem is, any tips or clues?

You lost me, how would I used a BFS to count the height? I tried with a BFS and had the same problem.

I tried this way and it still does not work.
[CODE]
int PBT::maxDepth() {
if (!root) {
return -1;
}
int depth=0;
int count=0;
stack<TreeNode >s;
TreeNode
nodePtr=root;
depth++;
s.push(nodePtr);
while (!s.empty()) {
nodePtr=s.top();
s.pop();
depth--;
if (nodePtr->right) {
s.push(nodePtr->right);
depth++;
}
if (nodePtr->left) {
s.push(nodePtr->left);
depth++
}
if (depth>count) {
count=depth;
}

}

return count;

}
[/CODE]

aaronmk2 Junior Poster in Training

I am trying to get the height of a BST using a stack. I was told that I should use preorder and measure find the largest size of the stack. However, this does not seem to work. Any ideas of what I am doing wrong.

[CODE]
int PBT::maxDepth() {
if (!root) {
return -1;
}
int depth=0;
stack<TreeNode >s;
TreeNode
nodePtr=root;
for (; ; ) {
while (nodePtr) {
s.push(nodePtr);
if (s.size() > depth)
depth = s.size();
nodePtr=nodePtr->left;
}if (s.empty()) {
break;
}
nodePtr=s.top();
s.pop();
nodePtr=nodePtr->right;
}
return depth;
}
[/CODE]

Thanks, I needed to change the path of php.ini field. Once I did that it worked fine

aaronmk2 Junior Poster in Training

I checked my php.ini file and there is no ; in front of extension=php_mysql.dll or extension=php_mysqli.dll. I think the I am getting this error because my figuration File (php.ini) Path is C:\Windows. How would I change it to C:\Apache2.2\php\php.ini? Also, once I have done this do I need to recompile my php and how would I do that. Also, would I need to use php.ini as my extension or could I just use C:\Apache2.2\php?

I am writing a program where it prints out how the freqeuncy of a word as long as the freqeuncy is in the fibonacci sequence (1,2,3,5,8,etc). I have figured out how to print all the words that appear once, however I am having trouble figuring out how to iterate so it prints out the words that have a higher freqeuncy.

[CODE]

def fib():
a,b = 0, 1
while 1:
yield b
a, b= b, a+b
import string
import itertools

while True:
filename=raw_input('Enter a file name: ')
if filename == 'exit':
break
try:
file = open(filename, 'r')
text=file.read()
file.close()
except:
print('file does not exist')
else:

    for word in string.punctuation:
        text=text.replace(word, "")
    word_list = text.lower().split(None)
    word_freq = {}

    for word in word_list:
        if len(word) > 1:
            word_freq[word] = word_freq.get(word, 0) + 1

    frequencies = sorted(word_freq.items(), key=lambda item: item[1])
    a=fib()
    order=sorted(word_freq.values())
    n=1
    a=next(a)
    for words in frequencies:
        try:
            if a ==words.index(n):
                print(words)
        except:
            print('nope')//how would I iterate here??

print('Bye')
[/CODE]

aaronmk2 Junior Poster in Training

I am trying to only have the words print out if they occur the same number of times as in the fibonacci sequence. If a words show up 1,2,3,5,8 etc then it will print up. I have gotten the program to print up the words based on how many times the appear. I am having trouble figuring out how to use the sequence in my program. Any tips or examples would be very appreciated.

[CODE]
def fib():
a,b = 0, 1
while 1:
yield a
a, b= b, a+b

from collections import Counter
import string

while True:
filename=raw_input('Enter a file name: ')
if filename == 'exit':
break
try:
file = open(filename, 'r')
text=file.read()
file.close()
except:
print('file does not exist')
else:

    for word in string.punctuation:
        text=text.replace(word, "")
    word_list = text.lower().split(None)
    word_freq = {}

    for word in word_list:
        if len(word) > 1:
            word_freq[word] = word_freq.get(word, 0) + 1

    print(sorted(word_freq.items(), key=lambda item: item[1])) 

// I am pretty sure something with the seqeunce should go into the above line
// but have been unable to figure it out.

print('Bye')
[/CODE]

aaronmk2 Junior Poster in Training

For this program I am trying to figure out how to sort/print the words out based on frequency of appearance in ascending order. As of now I can only get the words to sort/print based on alaphabetical order

[CODE]
from collections import Counter
import string

while True:
filename=raw_input('Enter a file name: ')
if filename == 'exit':
break
try:
file = open(filename, 'r')
text=file.read()
file.close()
except:
print('file does not exist')
else:

    for word in string.punctuation:
        text=text.replace(word, "")
    word_list = text.lower().split(None)
    word_freq = {}

    for word in word_list:
        word_freq[word] = word_freq.get(word, 0) + 1

    keys = sorted(word_freq.keys())
    for word in keys:
        if len(word) > 1:
            print (word, word_freq[word])//the words print out based on alphabetic order
            //how would I get them to print based on freqeuncy in ascending order?

print('Bye')[/CODE]

aaronmk2 Junior Poster in Training

I am trying to combine the string NCards and Scards into one string called Tcards.
I am using # include and I get an error. How would I fix this. All the variables are strings.

[CODE]

void deck::deal()
{
Tcards=strcpy(Scards, Ncards);

}[/CODE]

aaronmk2 Junior Poster in Training

I am reading in from a file and when I use .eof() it read everything from the file the I get a run time error of
Exc-Bad-Access. When I run a for loop instead the program runs with not errors. Any hints?
[CODE]
while (!inputFile.eof()) {

    inputFile>>number>>lowerRange>>higherRange>>cond>>aFName>>aLName>>phase;
    active=(cond=='t');
    sAds[i] =  SequenceAds(number, lowerRange, higherRange, active, aFName, aLName, phase);
    cout << sAds[i].getCost()<<" "<<sAds[i].getRangeLower()<<"-"<<sAds[i].getRangeHigher()<<" "<<sAds[i].getState()<<" "<<endl;
    i++;

}

[/CODE]
here is what is is reading in
45.85 54 74 t Interpublic Group introductory
31.84 20 50 f Mother Advertising end
22.90 18 25 t Pappas Group middle
40.30 65 80 t Omnicom Group end
22.15 50 64 f Grey EMEA introductory

I can include more code it it might help

included the curly bracket in my program forgot to put when I posted it

I am trying to have this read into the constructor

24.98 25 50 True
32.43 30 60 False
42.75 50 70 True

aaronmk2 Junior Poster in Training

I want to read in multiple lines from a file, but I am only able to get my program to read the first line. The program prints out two other lines but the values are zero.
[CODE]
double cost[3];
int lowerRange[3];
int higherRange[3];
bool active[3];
ifstream inClientFile("ad.txt", ios::in);
for (int i=0; i<3; i++) {
(inClientFile>>cost[i]>>lowerRange[i]>>higherRange[i]>>active[i]);
Ad ad(cost[i], lowerRange[i], higherRange[i], active[i]);
cout << ad.getCost()<<" "<<ad.getRangeLower()<<" "<<ad.getRangeHigher()
<<" "<<ad.getState()<<endl;
[/CODE]

What I am trying to do is get the file to read in four values, send them to the constructor and then prints them out. Any help is appreciated

aaronmk2 Junior Poster in Training

How do I display the results of list. I put rangeChecker objects in range and now I want to display the rangeChecker objects in range. How whould I do that?
[CODE]
static void display(RangeChecker[] rangeChecker, int SIZE)
{
//displays values for x, y, z, and how many times z was below x and y
int under = 0;
List range = new List();
range.Add(rangeChecker[0]);
under = rangeChecker[0].getUnder();
for (int i = 0; i < SIZE-1; i++)
{

            if (under == rangeChecker[i + 1].getUnder())
            {
                range.Add(rangeChecker[i+1]);
            }
            else if (under < rangeChecker[i + 1].getUnder())
            {
                range.Clear();
                under = rangeChecker[i + 1].getUnder();
                range.Add(rangeChecker[i + 1]);
            }

        }
        for(int i=0; i<range.Count(); i++)

    }[/CODE]

I tried using TryParse, but get a error in Visual Studio
Error 1 The name 'TryParse' does not exist in the current context
Copied and pasted the code from MSDN into Visual Studio and still got the same error

aaronmk2 Junior Poster in Training

I always thought that if I used a switch statement and enter an option not specified the default would catch it. However, if I press enter then enter an option I get a run time error. How would I fix this? I am only including part of the code, if you want to see the rest I can post the rest.

[CODE]

    public enum Options : byte
    {
        newZ = 1,
        display,
        Exit
    }
    static void displayMenu()
    {
        Console.WriteLine("Enter newZ to try new integers");
        Console.WriteLine("Enter display to see which Range Checker has the most Z's under the range");
        Console.WriteLine("Enter Exit to exit");
    }
    static void Main(string[] args)
    {
        RangeChecker[] rangeChecker = new RangeChecker[20];
        Random random = new Random();
        const int SIZE = 20;

        initialize(rangeChecker, SIZE);
        order(rangeChecker,  SIZE);

        for (; ; )
        {
            displayMenu();
            string volString = Console.ReadLine();
            Options options = (Options)Enum.Parse(typeof(Options), volString);
            switch (options)
            {
                case Options.newZ: 
                    addZ(rangeChecker, SIZE);
                    break;
                case Options.display:
                    display(rangeChecker, SIZE);
                    break; 
                case Options.Exit:
                    Console.WriteLine("Goodbye");
                    System.Environment.Exit(1);
                    break;
                default: 
                    Console.WriteLine("entry must be addZ, display, or Exit");
                    break;

            }
        }

    }
}

}[/CODE]

Z is a random integer that is tested to see where it falls in the range
of x and y. The reason why it looks like it was translated from C++ is
because all the previous classes I took were in C++.

What is my error is Display? The program runs.

aaronmk2 Junior Poster in Training

I am putting 20 objects in an array then I am using a bubble sort (not the most efficient, I know) to organize the set from highest to lowest. I am wondering if there is a way to do this without using sets (mutators)? Code is below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RangeChecker
{
    class RangeChecker
    {
        Random random = new Random();
        private int x =0;
        private int y = 0;
        private int under = 0;
        private int between = 0;
        private int over = 0;

        public RangeChecker()
        {

            x = random.Next(100);
            y = random.Next(100);
            while(x>y)
                x = random.Next(100);

        }

        public RangeChecker( int x, int y)
        {

            x = this.x;
            y = this.y;

        }

        // Precondition-none

        // Postcondtion-returns value of x
        public int getX()
        {
            return x;

        }

        // Precondition-none

        // Postcondtion-returns value of y
        public int getY()
        {
            return y;
        }

        // Precondition-none

        // Postcondtion-retruns if left value is smaller then right value

        public static bool operator <(RangeChecker op1, RangeChecker op2)
        {
            if ((op1.x < op2.x) && (op1.y < op2.y))
                return true;
            else if ((op1.x + op1.y) < (op2.x + op2.y))
                return true;
            else
                return false;
        }

        // Precondition-none

        // Postcondtion-retruns if left value is greater then right value
        public static bool operator >(RangeChecker op1, RangeChecker op2)
        {
            if ((op1.x > op2.x) && (op1.y > op2.y))
                return true;
            else if ((op1.x + op1.y) > (op2.x + op2.y))
                return true;
            else
                return false;
        }
        // Precondition-none

        // Postcondtion-x has new value
        public void setX(int x) 
        { ...
aaronmk2 Junior Poster in Training

I am trying to write a trigger that updates a column called CUST_BALANCE in a table called CUSTOMER when new data is entered into another table called INVOICE. What I want to do is when new data is inserted into INVOICE it will take the value in column INV_AMOUNT and add that to CUST_BALNCE in the CUSTOMER TABLE. Here is what I thought of
[CODE]
CREATE TRIGGER TRG_UPDATECUSTBALANCE//create the trigger
ON INVOICE //on the invoice table
AFTER INSERT//after ned data it inserted
UPDATE C//update customer table
SET C.CUST_BALANCE= C.CUST_BALANCE+ I.INV_AMOUNT//take cust_balance and add in INV_AMOUNT
FROM CUSTOMER C, INSERTED I //from inserted and customer tables
WHERE C.CUST_NUMBER= I.CUST_NUMBER//Where customer number is the same
[/CODE]

The error I am getting is that Update is being used in the wrong syntax. What am I doing wrong and how do I fix it?

Thanks, I was looking under enum switch, should have been looking for enum parse

aaronmk2 Junior Poster in Training

Is their a way where the user could type Low to use the enum instead of typing 1?
I know how to do this with strings, but am having trouble trying to figure it out using enums.

[CODE]
public enum Volume : byte
{
Low = 1,
Medium,
High
}

// shows different ways
// to work with enums
class Enumtricks
{
static void Main(string[] args)
{
// instantiate type
Enumtricks enumtricks = new Enumtricks();

    // demonstrates explicit cast
    // of int to Volume
    enumtricks.GetEnumFromUser();

    Console.ReadLine();
}

[/CODE]

Thanks

aaronmk2 Junior Poster in Training

I am using split to split a string into a int, int, string. When I try int, string, string my program works fine. When I try int, int , string I get a run time error of an input string was not in a correct format. I am leaving a note by were the code is that is giving me problems. It is in main. I am including my code for class in case it helps. The file I am reading in is 15 lines and in each line is 10(two ints) 15(two ints) PM(two letters).
this is my main
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace P3
{

class Program
{
    static void Main(string[] args)
    {

        int limit = 15;
        TimePiece [] timepiece = new TimePiece[limit];
        string line=" ";

        //int toggleCount;
        string filename = "f:\\date.txt";

        FileStream f = new FileStream(filename, FileMode.Open);
        StreamReader stream = new StreamReader(f);

        for (int i = 0; i < limit; i++)
        {
            //maybe bring in strin and do spit in constuctor.
            line = stream.ReadLine();    // header line
            string[] array = line.Split(' ');
            int milTime = Convert.ToInt32(array[0]);
            int pieceID = Convert.ToInt32(array[1]);//this is line giving me problems
            string tog = array[2];
            timepiece[i] = new TimePiece(milTime, pieceID, tog);

        }
        stream.Close();
        for (int i = 0; i < limit; i++)
        {

            timepiece[i].display();

        }

    }
}

}

[/CODE]
This is my class
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace P3
{
public class TimePiece
{
private static int num = 99;
private ...

When I pieceID to a string it runs fine, but when I try to part is I get a run time error, input string was not in a correct format.
This is main
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace P3
{

class Program
{
    static void Main(string[] args)
    {

        int limit = 15;
        TimePiece [] timepiece = new TimePiece[limit];
        string line=" ";

        //int toggleCount;
        string filename = "f:\\date.txt";

        FileStream f = new FileStream(filename, FileMode.Open);
        StreamReader stream = new StreamReader(f);

        for (int i = 0; i < limit; i++)
        {
            //maybe bring in strin and do spit in constuctor.
            line = stream.ReadLine();    // header line
            string[] array = line.Split(' ');
            int milTime = Convert.ToInt32(array[0]);
            int pieceID = Convert.ToInt32(array[1]);
            string tog = array[2];
            timepiece[i] = new TimePiece(milTime, pieceID, tog);

        }
        stream.Close();
        for (int i = 0; i < limit; i++)
        {

            timepiece[i].display();

        }

    }
}

}[/CODE]

This is the class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace P3
{
public class TimePiece
{
private static int num = 99;
private int ID;
private int hoursTime;
private int minute;
private string m;

    public TimePiece(int hoursTime, int minute, string m)
    {
        this.hoursTime = hoursTime;
        this.minute = minute;
        this.m = m;
        ID = num;
        num++;
    }

    public void display()
    {
        Console.WriteLine(hoursTime + " " + minute + " " + m +" " + ID);
    }
    //Precondition-none
    //Postcondition- ID is incremented by one.
    public int  IDnum()
    {
        num++;
        return num;
    }

}

}

It is just a simple text file [CODE]
06 OO AM
06 15 AM
06 OO PM
06 15 PM
07 OO AM
07 15 AM
07 OO PM
07 15 PM
08 OO AM
08 15 AM
08 OO PM
08 15 PM
09 OO PM
09 15 PM
10 OO AM
11 15 AM
11 OO PM
11 15 PM
[/CODE]

I am also having trouble parsing the second group of numbers when I use int pieceID = Convert.ToInt32(array[1]); I get a run time error input string is not in correct format

aaronmk2 Junior Poster in Training

I am getting this error object reference not set to an instance of an object and cannot figure out how to fix it. I can get the program to when I only have one Timepiece object, but when I try more I get the error message. I left a note of where the error is coming from in main

class program
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace P3
{
public class TimePiece
{
private static int num = 99;
private int ID;
private int hoursTime;
private string minute;
private string m;

    public TimePiece()
    {

    }
    public void Time(int hoursTime, string minute, string m)
    {
        this.hoursTime = hoursTime;
        this.minute = minute;
        this.m = m;
        ID= num;
        num++;
    }

    public void display()
    {
        Console.WriteLine(hoursTime + " " + minute + " " + m +" " + ID);
    }   
}

}
[/CODE]

main
[CODE]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace P3
{

class Program
{
    static void Main(string[] args)
    {

        int limit = 15;
        TimePiece []timepiece = new TimePiece[limit];
        string line=" ";

        //int toggleCount;
        string filename = "f:\\date.txt";

        FileStream f = new FileStream(filename, FileMode.Open);
        StreamReader stream = new StreamReader(f);

         for (int i = 0; i < limit; i++)
        {
            //maybe bring in strin and do spit in constuctor.
            line = stream.ReadLine();    // header line
            string[] array = line.Split(' ');
            int milTime = Convert.ToInt32(array[0]);
            string pieceID = array[1];
            string tog = array[2];
            timepiece[i].Time(milTime, pieceID, tog);//this is the line that causes the error
        }
        stream.Close(); ...

[QUOTE=Mitja Bonca;1436217]Maybe this will do? :
[CODE]
string filename = "f:\date.txt";
using (StreamReader stream = new StreamReader(filename))
{
string line;
while ((line = stream.ReadLine()) != null)
{
string[] array = line.Split(' ');
int a = Convert.ToInt32(array[0]); //1.
string b = array[1]; //2.
string c = array[2]; //3.
}
}
[/CODE][/QUOTE]

Thanks I never thought about splitting the string.