Moderators: phlip, Moderators General, Prelates
EvanED wrote:The other is to use macro hackery. If you define your implementation in a header file, you can arrange things so that something like
- Code: Select all
#define HEAP_DATA_TYPE double
#include "my_heap.h"
(I suggest actually undefining HEAP_DATA_TYPE in my_heap.h, but that's personal preference. There is a reason though -- it seems like it would reduce the risk of including my_heap.h with the wrong type.)
I think the latter option sucks less, but that's me. (It means that merely the implementation of your heap is terrible, whereas with a void* interface, the use of it is as well.)
Rysto wrote:EvanED wrote:The other is to use macro hackery. If you define your implementation in a header file, you can arrange things so that something like
- Code: Select all
#define HEAP_DATA_TYPE double
#include "my_heap.h"
(I suggest actually undefining HEAP_DATA_TYPE in my_heap.h, but that's personal preference. There is a reason though -- it seems like it would reduce the risk of including my_heap.h with the wrong type.)
I think the latter option sucks less, but that's me. (It means that merely the implementation of your heap is terrible, whereas with a void* interface, the use of it is as well.)
Lame. This is how you implement a type-safe, generic data structure in C.
EvanED wrote:Also: never run a SunOS box.
Red Hal wrote:If you can't tick all the boxes then you don't have privilege! Privilege; it's a multiple-input AND gate!
rath358 wrote:Thought of a maybe slightly better than brute force way to do that huge find the highest possible sum path through the triangle problem from project Euler. A shame I have real-world things like finals to worry about...
roband wrote:Mav is a cow.
RoadieRich wrote:Brute force is closer to O(n!), I think.
RoadieRich wrote:rath358 wrote:Thought of a maybe slightly better than brute force way to do that huge find the highest possible sum path through the triangle problem from project Euler. A shame I have real-world things like finals to worry about...
There is a very neat method to solve that one. Gives you a runtime of O(n^2), where n is the number of rows. Brute force is closer to O(n!), I think.
RoadieRich wrote:rath358 wrote:Thought of a maybe slightly better than brute force way to do that huge find the highest possible sum path through the triangle problem from project Euler. A shame I have real-world things like finals to worry about...
There is a very neat method to solve that one. Gives you a runtime of O(n^2), where n is the number of rows. Brute force is closer to O(n!), I think.
Thesh wrote:It should be O(n2n-1). There's two choices each step down, but no choice for the first row.
You, sir, name? wrote:If you have over 26 levels of nesting, you've got bigger problems ... than variable naming.
suffer-cait wrote:it might also be interesting to note here that i don't like 5 fingers. they feel too bulky.
tastelikecoke wrote:Freshie CS student here. What do you think would be a good example of a real life CS problem? I just want an idea on what you would call a practical problem, and probably try solving it
roband wrote:Mav is a cow.
RoadieRich wrote:It depends on how deep you want to go. I'm guessing "Freshie" means you've just started?
//Whamjacked!tes wrote:I'm learning Java, and it seems a bit wrong to me that you can't access private member variables of the parent class in a subclass. When I want to override a function using those member variables, how should I do it? From what I understand of encapsulation, these variables shouldn't be accessible outside the parent class and subclasses, so public get and set methods are not an option. When I use protected, all classes in the same package can access the variables.
roband wrote:Mav is a cow.
EvanED wrote:Java protected doesn't act like C++ protected. (Regardless of inheritance relationships, Java protected only allows access to other classes in the same package.)
I think the way to look at this is that Java is protecting against actual deliberate, malicious attempts to access those semi-private variables. (This is important because a lot of important things like their security manager depend on the integrity of those variables!) And from that point of view, C++ protected variables might as well be public, because to some extent if you wanted to access one you could just make a subclass and do so. Whereas on the C++ side, they can't really protect against access at all, because you can do horrible-but-working stuff like #define private public or synthesizing pointers to the private members.
EvanED wrote:Java protected doesn't act like C++ protected. (Regardless of inheritance relationships, Java protected only allows access to other classes in the same package.)
I think the way to look at this is that Java is protecting against actual deliberate, malicious attempts to access those semi-private variables. (This is important because a lot of important things like their security manager depend on the integrity of those variables!) And from that point of view, C++ protected variables might as well be public, because to some extent if you wanted to access one you could just make a subclass and do so. Whereas on the C++ side, they can't really protect against access at all, because you can do horrible-but-working stuff like #define private public or synthesizing pointers to the private members.
The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
roband wrote:Mav is a cow.
CameraAnimator::CameraAnimator(SceneNode* cameraNode,
btDynamicsWorld* world,
BaseApplication* application,
float movementSpeed, float turningSpeed,
InputMethod inputMethod):
mCameraNode(cameraNode),
mWorld(world),
mApplication(mApplication), 

roband wrote:Mav is a cow.


RoadieRich wrote:If I want a thread to pause its processing loop, with the option of resuming it on an external event, which of the many c# thread control classes is most appropriate? I wanted to use Thread.suspend() and Thread.Resume(), but they're raising empty exceptions (as in no message at all), and a look at the docs shows them as deprecated.
(It's for a threaded software pwm on a netduino, and when the output is 0 or 100%, I want to stop the Write/sleep cycle.)
roband wrote:Mav is a cow.
public class SoftwarePWM : OutputPort
{
public SoftwarePWM(Cpu.Pin portID, bool initialState)
: base(portID, initialState)
{ }
private Thread _t;
private int _b;
public void Write(int brightness)
{
_t = new Thread(modulate);
_b = brightness <= 100 ? brightness : 100;
switch (_b)
{
case 0:
base.Write(false);
break;
case 100:
base.Write(true);
break;
default:
if (!_t.IsAlive)
_t.Start();
break;
}
}
private void modulate()
{
int i;
while (_b > 0 && _b < 100)
{
base.Write(true);
//for (i = 0; i < _b; i++) { }
Thread.Sleep(_b);
base.Write(false);
//for (; i <= 100 - _b; i++) { }
Thread.Sleep(100 - _b);
}
}
}roband wrote:Mav is a cow.
if (_t == null) _t = new Thread (modulate);Users browsing this forum: Fekeenuisance, shealtket, Slageammalymn and 5 guests