|
I have an assignment where I had to make a queue (without using the STL ) using a linked list. The queue class I made is supposed to represent an airport in the assignment and the nodes are the planes, ect. That part works fine and I can remove and add 'planes' perfectly. However the second part is driving me nuts. Pretty much for the second part of the assignment I need to turn the three queues into a single queue, based on whichever queue has the highest 'passenger' integer. The story is that the airport got snowed in but they have a reserve runway to use and are letting planes from the other three runways go, depending on which has the highest amount of passengers. I was messing around trying to figure something out and I did manage to make a function that calls the three queues by reference and then compares the queues to see which one has the highest 'passenger' integer. It also returns a value of 1, 2, or 3, depending on which queue it came from. Then in the main, I have some if/else statements which calls the remove function for whichever queue that the integer returned refers to. However here is my problem. Once all of the nodes in the queue are removed, I get an exception error because I am still calling the three queues by reference in my function that checks to see which queue has the highest 'passenger' integer. Because of that, it tries to read information from a null queue and crashes. Is there a way to get the function to ignore an empty queue? The program would work fine if it wasn't for this (it does function perfectly until one of the queues is empty). I can definitely post (on pastebin) my terrible mess of code if anyone is interested. edit: or any other suggestions are welcome. I dont mind completely redoing the code if it makes sense. Stealthgerbil fucked around with this message at 09:30 on Oct 28, 2009 |
# ? Oct 28, 2009 09:18 |
|
|
# ? May 19, 2024 08:39 |
|
Stealthgerbil posted:I have an assignment where I had to make a queue (without using the STL ) using a linked list. The queue class I made is supposed to represent an airport in the assignment and the nodes are the planes, ect. That part works fine and I can remove and add 'planes' perfectly. You might as well post some code - either your design is muddled or just your explanation is.
|
# ? Oct 28, 2009 10:17 |
|
Stealthgerbil posted:edit: or any other suggestions are welcome. I dont mind completely redoing the code if it makes sense. Well why not have a way of asking the queue if it's empty or not. Then you have something like: code:
I'm not saying this design is particularly good, but from the code you're describing it sounds like it might be the most simple to implement.
|
# ? Oct 28, 2009 14:42 |
|
Nomnom Cookie posted:Your code is using O(n*log(n)) space. Mergesort is an O(n) space algorithm. Well that's Interesting. And what is space? Is that the memory i'm using? Last i checked big O dealt with time and not space. I may not know c++ but please don't question my algorithms. Speaking of not knowing c++, i'm getting an unhandled exception here and i'm not sure where. It should be a problem with memory/pointers but my debugger isn't pointing anywhere in the code when it breaks, just shows me a memory location: code:
Unhandled exception at 0x6812f8bc (msvcr90d.dll) in qsort.exe: 0xC0000005: Access violation reading location 0x555c3a63. The program '[4684] qsort.exe: Native' has exited with code 0 (0x0).
|
# ? Oct 28, 2009 17:31 |
|
kingcrimbud posted:Last i checked big O dealt with time and not space. Edit: That occurred to me too VVVV BigRedDot fucked around with this message at 17:51 on Oct 28, 2009 |
# ? Oct 28, 2009 17:48 |
|
kingcrimbud posted:Well that's Interesting. And what is space? Is that the memory i'm using? Last i checked big O dealt with time and not space. I may not know c++ but please don't question my algorithms.
|
# ? Oct 28, 2009 17:49 |
|
kingcrimbud posted:Well that's Interesting. And what is space? Is that the memory i'm using? Last i checked big O dealt with time and not space. I may not know c++ but please don't question my algorithms. From your own link: quote:Worst case space complexity: Θ(n)
|
# ? Oct 28, 2009 17:50 |
|
Lexical Unit posted:We are getting trolled so hard right now.
|
# ? Oct 28, 2009 18:20 |
|
kingcrimbud posted:Well that's Interesting. And what is space? Is that the memory i'm using? Last i checked big O dealt with time and not space. I may not know c++ but please don't question my algorithms. Well, I think we finally found the problem here: you're illiterate.
|
# ? Oct 28, 2009 18:34 |
|
kingcrimbud posted:
2) sizeof (to my knowledge) is calculated at compile time and I was pretty sure a dynamically allocated array being sizeof'd throws a compiler error. Maybe I'm wrong on that but either way that's the first thing I'd look at re: crashing.
|
# ? Oct 28, 2009 23:43 |
|
Bhaal posted:1) sizeof returns the total size of the array, so sizeof(float[10]) is going to be 40 for a 4 byte float. Better approaches are to use sizeof(array)/sizeof(<type>), or better yet, keep track of a given array's size in an integer and just use that to grab a random element, etc. Incorrect on both counts*. However, as I'm not apt to do people's homework for them, I will leave the correct answer as an exercise to the reader. * Well the first one is technically correct but not applicable to the situation.
|
# ? Oct 28, 2009 23:47 |
|
A question about time. Basically i am working on my game and want to store the current hour/minute/second of the ingame time. I have a timer that currently returns the timedelta(ms) between updates. E.g: m_CurrentMilliseconds = (Timer::GetTimeDelta() * m_Rate); Is there something better then me doing the conversions manually by myself?
|
# ? Oct 29, 2009 01:09 |
|
Dammit, guys, I thought we all had a tacet agreement to ignore kingcrimbud's whining, it was going so well too
|
# ? Oct 29, 2009 02:34 |
|
UberJumper posted:A question about time. Basically i am working on my game and want to store the current hour/minute/second of the ingame time. I have a timer that currently returns the timedelta(ms) between updates. Why don't you just add a new member to your Timer class that does this exact functionality? Somehow you're keeping track of the number of ms from one frame to the next, it shouldn't be hard to add a function that just returns the current ms since startup or whatever (add up all the deltas?).
|
# ? Oct 29, 2009 08:42 |
|
There's a solution that involves templates here...
|
# ? Oct 29, 2009 08:52 |
|
kingcrimbud posted:
|
# ? Oct 29, 2009 10:33 |
|
Veritron posted:i know there's some kind of tacit agreement to ignore you going on here, but you are like some kind of reverse genius please don't question my algorithms
|
# ? Oct 29, 2009 11:00 |
|
Veritron posted:i know there's some kind of tacit agreement to ignore you going on here, but you are like some kind of reverse genius His code reads like poetry, specifically limericks.
|
# ? Oct 29, 2009 15:33 |
|
ctz posted:please don't question my algorithms or our commitment to sparklemotion.
|
# ? Oct 29, 2009 18:42 |
|
I keep expecting to see a screenshot of this thread in the "things you're working on" thread. "I created an AI to write a C++ program using Markhov Chains".
|
# ? Oct 29, 2009 22:37 |
|
I'm trying to track down a viral #define someone introduced into the nightmare that is our codebase. What trick can I use to figure out where the #define is located?
|
# ? Oct 30, 2009 12:47 |
|
Lexical Unit posted:I'm trying to track down a viral #define someone introduced into the nightmare that is our codebase. What trick can I use to figure out where the #define is located? grep -R \#define | grep FOO
|
# ? Oct 30, 2009 13:00 |
|
Lexical Unit posted:I'm trying to track down a viral #define someone introduced into the nightmare that is our codebase. What trick can I use to figure out where the #define is located? cpp -DYOURMACRO someaffectedfile.c | grep redefined (or make CPPFLAGS=-DFOO | grep redefined)
|
# ? Oct 30, 2009 13:01 |
|
Zakalwe posted:grep -R \#define | grep FOO Edit: Nevermind Got the list of included files by parsing it out of the preprocessor output. Lexical Unit fucked around with this message at 13:55 on Oct 30, 2009 |
# ? Oct 30, 2009 13:30 |
|
Lexical Unit posted:Our build system sucks so much oh god.
|
# ? Oct 30, 2009 13:53 |
|
I have a question about debugging vectors: I recently had to change stl header files in order to make the use of the [] operator behave more like at() and tell me when indices went beyond the size of the vector. Is there a way I could have done this without changing the header files? I'm using gcc 4.1. Also, I wasn't able to get any output which told me where exactly the error was as any assert I added reported the error in the stl header file not the code that was using an invalid index.
|
# ? Oct 31, 2009 00:10 |
|
mincepiesupper posted:I have a question about debugging vectors: I recently had to change stl header files in order to make the use of the [] operator behave more like at() and tell me when indices went beyond the size of the vector. Is there a way I could have done this without changing the header files? I'm using gcc 4.1. #define _GLIBCXX_DEBUG
|
# ? Oct 31, 2009 00:23 |
|
Will this work with a release build? The code I am having the problem with is not mine, what I've been given to build it with is for release builds only. I've also been told that debug builds don't work but I've not yet tried this to see exactly what 'don't work' means.
|
# ? Oct 31, 2009 00:36 |
|
mincepiesupper posted:Will this work with a release build? The code I am having the problem with is not mine, what I've been given to build it with is for release builds only. I've also been told that debug builds don't work but I've not yet tried this to see exactly what 'don't work' means. If you can change <vector> to hack in your own debugging, you have enough to build with the debug version of libstdc++ instead.
|
# ? Oct 31, 2009 02:04 |
|
Is there a good library for C++ that does immutable strings? That is I want Java type strings where underlying char array doesn't change. The reason is that I am working with very large strings, and in course of my computations a lot of substrings are returned. The big text however, never changes. Right now the library I am forced to use uses STL strings, which I believe to not be immutable. So if my data structure needs to return a substring from the large source text it would need to do copy every time. With immutable strings, the returned string object would only have to contain reference to underlying char array and two indecies. Am I better off implementing my own immutable string class?
|
# ? Oct 31, 2009 19:15 |
|
const char *
|
# ? Oct 31, 2009 20:30 |
|
Avenging Dentist posted:const char * That is not what I want. I want a wrapper around char that will act like normal std::string in most ways except that it would share underlying char * with other strings and substr operation would be really fast on it.
|
# ? Oct 31, 2009 20:39 |
|
RussianManiac posted:That is not what I want. I want a wrapper around char that will act like normal std::string in most ways except that it would share underlying char * with other strings and substr operation would be really fast on it. code:
|
# ? Oct 31, 2009 20:43 |
|
Is there a sign function? i.e. sign(-2.3) -> -1 I've always just done val/abs(val), but this is a little gross / bad if val == 0.
|
# ? Oct 31, 2009 22:59 |
|
Contero posted:Is there a sign function? i.e. sign(-2.3) -> -1 1) It's usually called sgn 2) It's not there, but that's because it's trivial to write an efficient version: (x>0) - (x<0)
|
# ? Oct 31, 2009 23:01 |
|
Contero posted:Is there a sign function? i.e. sign(-2.3) -> -1 There is a signbit(). Seems like C99 if I am reading this right: http://www.opengroup.org/onlinepubs/000095399/functions/signbit.html ... Note that I am sure of what it does for negative 0. Maybe that's negative, and positive 0 is positive?
|
# ? Oct 31, 2009 23:05 |
|
pre:DESCRIPTION signbit() is a generic macro which can work on all real floating-point types. It returns a non-zero value if the value of x has its sign bit set. This is not the same as x < 0.0, because IEEE 754 floating point allows zero to be signed. The comparison -0.0 < 0.0 is false, but sign‐ bit(-0.0) will return a non-zero value.
|
# ? Oct 31, 2009 23:18 |
|
RussianManiac posted:http://en.wikipedia.org/wiki/Rope_(computer_science) If you have large strings you may find ropes to be a useful representation of them quote:Am I better off implementing my own immutable string class? Signs point to no. tef fucked around with this message at 16:12 on Nov 1, 2009 |
# ? Nov 1, 2009 16:10 |
|
tef posted:http://en.wikipedia.org/wiki/Rope_(computer_science) This would be a lot worse for my problem, as substring takes logarithmic time using ropes and using immutable string it will be constant. Oh well, I guess I will just implement my own very simple immutable string class. All I have is just a giant string that never changes, and a bunch of operations that work and/or return with substrings of this immutable string.
|
# ? Nov 1, 2009 22:28 |
|
|
# ? May 19, 2024 08:39 |
|
RussianManiac posted:This would be a lot worse for my problem, as substring takes logarithmic time using ropes and using immutable string it will be constant. Oh well, I guess I will just implement my own very simple immutable string class. All I have is just a giant string that never changes, and a bunch of operations that work and/or return with substrings of this immutable string.
|
# ? Nov 2, 2009 00:06 |