User Profile
Collapse
-
AVL (Height Balanced) Tree
I have to code Insert/Remove for and AVL tree derived from a BST. I have a fully functional Insert working. Do determine the heights, I call a Height function that recursively calculates the height of each node. Does this violate the constraints on an AVL tree that all functions are to run in O(log n)? -
AVL Tree Insertion/Removal Repairs
I have Insert, Remove, RotateLeft, and RotateRight all tested and functioning. However, the Insert/Remove are derived from a Binary Search Tree. I'm really lost as to how to determine when and where to call the Rotate functions after my calls to Insert and Remove to make the tree balanced between -1 and 1. I read the wiki article but it didn't do much for me. What advice can you give on the topic or what recommended site can I visit for a nice concrete... -
Bit masking
I have a 32bit number (unsigned int), I want to set another 32bit number to only a certain series of bits. For instance:
1000 0000 1011 1010 0111 1001 1101 0011 is what is given.
I want to set another number to bits 3 - 16 from the left, so bits 17 - 30.
I tried newNum = (given & 0x3FFF0000) but it is incorrect.
1000 0000 1011 1010 0111 1001 1101 0011given
... -
Accessing functions of another file
In a simple form, I fully understand how to do this.
Code://foo.h class Foo; Class Foo { void someFunction(int); } //foo.cpp #include <foo.h> int main() { Foo foo; foo.someFunction(bar); ... return 0;
Code://foo.h ... namespace myStuff { template typename
-
Use Iterator to obtain vector index
I am creating a sorted vector using lower_bound. I set an Iterator to lower_bound to determine the place a 'val' needs to be. I then PushBack(val) to create the needed space for the item. I have tried several methods to then move the the 'val' from the back to it's lower_bound location, but either get a segfault or the items are not in "less than" order. I can easily do this using the 'index' of the items vs. trying to use Iterators. How... -
Code sample will be posted around 8:00pm EST. I'm in class now -
-
Yes, I have a stack that I push unvisited cells to, when it reaches a dead end, it breaks.Leave a comment:
-
Backtrack in maze
I have a maze setup by rows and columns.
0 1 2 3 4 5
6 7 8 9 10 11...
Given a starting point and an ending point of say start = 0 and goal = 8
Each cell has a list of its cells that it has access to, no walls between.
I begin solving the maze by starting at start and going to its next possible cell, the lowest numbered one. So if cell 3 has access to 4 and 9, it goes to 4. I then 'mark'... -
Code:int a(3), S, R; for (S=1; S <=5; S+=2) { R=2 N=((2^R)*S)+1 if (int(((a^S)-1)/((2^R)*S+1))==((a^S)-1)/N) std::cout<< "yes\n" << "S= " << S << "\nR= " << R << "\na= " << a; else std::cout << "no"; }
Leave a comment:
-
Banfa, thanks, but I was going in the wrong direction with that.
However, say I have
Code:class Foo { Bar * start; start = &fooVector[size_t] ... } class Bar { ... }
Leave a comment:
-
So, say that the void Add(Foo * N) function has access to a private variable that is a list and I want to add more than one item at any given item in the list. For instance, I want to add a North, and South to item 0 in the list, how can I do this?Leave a comment:
-
-
Passing pointer as parmaneter
I have to pass a pointer as a parameter, but I can't quite get the syntax down.
I have this variable:
std::vector<Foo > fooVector;
And this function of another class, Foo
void Add (Foo * N)
So I need to pass fooVector_[size_t] to the Add function.
I have tried this:
Foo foo;
foo.Add(foo.foo Vector_[size_t]) but get the error (shortened) Needs class::Foo*... -
const char* and char* concatenation
I am trying to concatenate these two items and I get an error about binary conversion.
This is how I have it set up:
bool concatenate (const char* foo, char* bar)
const char* foobar = foo + bar -
Reads input endlessly
I have a program to read in words and sort those words into lexicographical order. The problem I have is that it reads the input file endlessly. I know it does not reach the output section because the output file is not created.
Code:size_t maxArraySize = 1000; int main (int argc, char* argv[]) { char* a [maxArraySize]; unsigned int count = 0; if (argc < 3) //checks
-
Is it the addess of the variable or is it passed by reference? I couldn't find much about & online.Leave a comment:
-
I can see that you can change the value of the & variable, that it.Leave a comment:
-
Pointer and integer expressions
I have a review test question and was wondering why the answers are the way they are. Could someone please explain what you can and cannot do with the following?
Which of the following expressions are allowed, given that i and j are pointers to the same type and n is an integer?
n = i / j
n = j - i correct?
n = i % j
n = i + j
n += j
j += n correct?... -
Why?
I was wondering why the output of the following code is:
x = 1
y = 2
z = 3
x = 2 (understand here up)
y = 2 (Why isn't it 3)
z = 5 (Why isn't it 4)
Code:int F(int& x, int y) { x = x+1; y = y +1; return x + y; } int main() { int x, y, z; x = 1, y = 2, z = 3; std::cout << "x=" << x << '\n'
No activity results to display
Show More
Leave a comment: