Computer Science Canada Why this dies |
Author: | Tubs [ Thu Jan 19, 2006 9:16 pm ] | ||
Post subject: | Why this dies | ||
Why does this program die a horribly gruesome death? |
Author: | wtd [ Thu Jan 19, 2006 9:29 pm ] | ||
Post subject: | |||
What did I do differently? |
Author: | Tubs [ Thu Jan 19, 2006 9:46 pm ] |
Post subject: | |
Changed the parameter to a pointer and dynamically allocated memory for the variable? |
Author: | Tubs [ Thu Jan 19, 2006 9:47 pm ] |
Post subject: | |
that code is giving me errors!!! line 19 makes a pointer from integer without a cast |
Author: | wtd [ Thu Jan 19, 2006 9:55 pm ] |
Post subject: | |
Yes, returning a pointer to stack-allocated memory inside a function results in bad things happening. I don't get any such error using GCC. Show me the exact code you were using. |
Author: | Tubs [ Thu Jan 19, 2006 9:58 pm ] |
Post subject: | |
wtd wrote: Yes, returning a pointer to stack-allocated memory inside a function results in bad things happening.
I don't get any such error using GCC. Show me the exact code you were using. The one you posted. |
Author: | wtd [ Thu Jan 19, 2006 10:04 pm ] |
Post subject: | |
Then I cannot help. The code I posted compiles flawlessly with GCC 3.4.2 (MinGW). |
Author: | Tubs [ Fri Jan 20, 2006 1:01 am ] | ||
Post subject: | |||
Ok, I got the code working. IDEs are foolish. Another question: how would I go about making a function that finds a certain item in a linked list, given the number it is in order and a pointer to the beginning of the list? This is what I have so far:
|
Author: | wtd [ Fri Jan 20, 2006 1:13 am ] |
Post subject: | |
Use a loop to follow the links? |
Author: | Tubs [ Tue Jan 24, 2006 7:29 pm ] | ||
Post subject: | |||
Yeah, thanks. New question if I may: A sequence is defined by the following recursive relationship: A(n) = A(n/2) + A(n/2) ; A(1) = 3 It is defined only for powers of 2 and you need only consider powers of two. I don't think I know what they are asking here, this is my code so far:
Help greatly appreciated |
Author: | wtd [ Tue Jan 24, 2006 7:34 pm ] |
Post subject: | |
Look at that code really closely. Now... remove all of the code inside the functions, leaving just the headers? See the problem? |
Author: | Tubs [ Tue Jan 24, 2006 8:03 pm ] |
Post subject: | |
wtd wrote: Look at that code really closely.
Now... remove all of the code inside the functions, leaving just the headers? See the problem? Yeah, I was fooling around with the types because the question seemed to imply that that ints were ok, but there is division by 2 thrown in there. When I change it to double type it outputs 0, when it is an integer, 1. I'm still lost. |
Author: | wtd [ Tue Jan 24, 2006 9:58 pm ] | ||
Post subject: | |||
What they're saying is... when n is 1, A returns 3. For any other value of n, well... the question explains that. So, let's look at a breakdown of A(8).
|
Author: | Tubs [ Tue Jan 24, 2006 10:25 pm ] |
Post subject: | |
Thanks a lot wtd. You rock. |
Author: | wtd [ Tue Jan 24, 2006 10:52 pm ] | ||
Post subject: | |||
Glad I could help.
|
Author: | Tubs [ Tue Jan 24, 2006 10:56 pm ] |
Post subject: | |
I have no idea what code that is. |
Author: | wtd [ Tue Jan 24, 2006 11:12 pm ] |
Post subject: | |
It's Common Lisp. It's my way of just posting the answer. |
Author: | Tubs [ Tue Jan 24, 2006 11:22 pm ] | ||
Post subject: | |||
Weird. This function is still eluding me. (Recursion is not my fort'e) Any tips at all? Currently if a power of 2 is inserted it returns n.
|
Author: | wtd [ Tue Jan 24, 2006 11:29 pm ] | ||||
Post subject: | |||||
Your use of a variable here is not a good habit to get into.
You're returning 1 here if n equals 1. Is that what the problem says should happen? |
Author: | Tubs [ Tue Jan 24, 2006 11:37 pm ] |
Post subject: | |
Yeah, I thought the A(1) = 3 was just an example to show that you were on the right track. Also, I followed the format provided in my text book on how to do a recursive fibonacci sequency and it used an 'ans' variable. Thanks again |
Author: | Martin [ Wed Jan 25, 2006 2:57 am ] | ||||||||||||
Post subject: | |||||||||||||
As I have recently discovered
Which of the following will crash?
|
Author: | wtd [ Wed Jan 25, 2006 3:07 am ] |
Post subject: | |
Unfortunately this is sacrificing expressivity of the code to compensate for a [potential ambiguity in C++'s syntax. It is vastly more natural to think "n == 1". Here "n" is emphasized because it is the subject. We're not interested in whether 1 equals "n". We're interested in whether "n" equals 1. Technically speaking, they're entirely equivalent. However, there is a linguistic factor in writing good code. |
Author: | Martin [ Wed Jan 25, 2006 9:40 pm ] |
Post subject: | |
Well the easy solution is to start thinking in Japanese. |
Author: | Hikaru79 [ Wed Jan 25, 2006 10:47 pm ] |
Post subject: | |
Martin wrote: Well the easy solution is to start thinking in Japanese.
That'd be closer to "n 1 ==" |
Author: | Tubs [ Thu Jan 26, 2006 9:33 pm ] | ||
Post subject: | |||
This code is telling me that data.name and next are not part of a structure or union, which is almost definately because I have some incorrect pointer usage somewhere, but I get all confuzzeled when it comes to double pointers. Any tips? (I would post the program in its entirety but it is a heirchy of many functions)
|
Author: | wtd [ Thu Jan 26, 2006 9:54 pm ] |
Post subject: | |
And without seeing the definition of these data structures, I'm supposed to tell you what about this code? |
Author: | Tubs [ Thu Jan 26, 2006 9:58 pm ] |
Post subject: | |
Just wondering if there was any obvious misuse of pointer syntax. Here is the whole file: |
Author: | Tubs [ Thu Jan 26, 2006 11:21 pm ] |
Post subject: | |
Misuse of pointer syntax such as not putting brackets around *list Fixed linker problem with having extraneous functions, now it dumps core after running, is'nt that great. |
Author: | wtd [ Thu Jan 26, 2006 11:35 pm ] |
Post subject: | |
I've gotten spoiled. That level of pointer indirection is making my head hurt. |
Author: | wtd [ Thu Jan 26, 2006 11:37 pm ] | ||
Post subject: | |||
You have:
In the function you pasted here. This is in void context and does nothing. Why do you have it there? |
Author: | Tubs [ Thu Jan 26, 2006 11:52 pm ] |
Post subject: | |
I thought it would select the next coaster for the delete function to work with. I've been doing this assignment for about 6 hours now so my head hurts too functions still to go: - duplicate one node to another node - duplicate a list to another list - reverse a list |
Author: | Tubs [ Fri Jan 27, 2006 12:00 am ] |
Post subject: | |
This may be my tiredness / burntoutedness setting in, but I really really appreciate the help wtd. You're the man. |
Author: | wtd [ Fri Jan 27, 2006 3:12 pm ] |
Post subject: | |
Glad I can help even if only a little bit. My suggestion... write one function at a time. Make sure that function works. Then move on. |
Author: | Tubs [ Thu Feb 02, 2006 12:53 pm ] |
Post subject: | |
When using linked lists, how would you make a loop so that the current node is changed by a power of 2 in every iteration? (Creating a 'galloping search') ex. currentnode->next // changed by one currentnode->next->next // changed by two |
Author: | wtd [ Thu Feb 02, 2006 2:10 pm ] | ||
Post subject: | |||
Generalize psuedocode for dealing with linked list iteration.
|
Author: | Tubs [ Thu Feb 02, 2006 3:11 pm ] |
Post subject: | |
This is a sorted list so I dont want a linear search, i want to increase the current node by a power of 2 in each iteration til the value of that node is greater than the target, in which case i run a linear search from the previous power of 2 to the current power of 2 until the node with the target is found. |
Author: | Andy [ Thu Feb 02, 2006 3:32 pm ] |
Post subject: | |
have a for loop that increaes exponentially each time, then inside, have another for loop that goes from 1 to the first counter, and inside the second for loop, do your getNext stuff |
Author: | Tubs [ Thu Feb 02, 2006 9:47 pm ] | ||
Post subject: | |||
I'm getting there, but the list that I am supposed to use seems not to finish declaring itself. can anyone tell me whats wrong?
|
Author: | wtd [ Thu Feb 02, 2006 10:24 pm ] | ||||
Post subject: | |||||
This is one of the more inane things I've ever seen.
Why are you dereferencing the return value of insert_int_list in a void context? |
Author: | wtd [ Thu Feb 02, 2006 10:25 pm ] | ||||
Post subject: | |||||
wtd wrote:
This is one of the more inane things I've ever seen. Errrr... I meant:
|
Author: | Tubs [ Thu Feb 02, 2006 10:26 pm ] |
Post subject: | |
Yeah i was wondering about that as well. i guess its just to get us used to declaring the structure and stuff. |
Author: | Tubs [ Thu Feb 02, 2006 10:29 pm ] |
Post subject: | |
As for the dereferencing, I get the same error when i change it. |
Author: | wtd [ Thu Feb 02, 2006 10:30 pm ] |
Post subject: | |
An additional note is that you should not, by any means, be casting the return value of malloc. |
Author: | wtd [ Thu Feb 02, 2006 10:32 pm ] |
Post subject: | |
Tubs wrote: As for the dereferencing, I get the same error when i change it.
Yes, it's likely not the source of the error, but it is worth pointing out. |
Author: | Tubs [ Thu Feb 02, 2006 10:38 pm ] |
Post subject: | |
i only wrote the main of this stuff, the rest was supplied by my prof for this assignment. its kinda hard to do this when the supplied material doesnt work. |
Author: | wtd [ Thu Feb 02, 2006 10:48 pm ] |
Post subject: | |
Indeed. |
Author: | Tubs [ Thu Feb 02, 2006 10:55 pm ] |
Post subject: | |
So no idea why its not declaring the end of the list properly? |
Author: | wtd [ Thu Feb 02, 2006 11:00 pm ] |
Post subject: | |
I have no idea why anything in that library is written the way it is. |
Author: | Tubs [ Thu Feb 02, 2006 11:01 pm ] |
Post subject: | |
Yeah. Fuck the library i'm making my own damn list. Excuse my french. |
Author: | Tubs [ Sun Feb 12, 2006 8:48 pm ] |
Post subject: | |
I cannot figure out why this program dies (no error messages on my IDE either ) Any help is greatly appreciated as always The program is supposed to take an integer, use the division by 2 method to determine the binary equivalent using stacks. |
Author: | Tubs [ Sun Feb 12, 2006 10:26 pm ] |
Post subject: | |
Scratch that last post. Re-wrote program. Linked lists suck. |
Author: | Tubs [ Thu Mar 30, 2006 9:55 pm ] | ||||
Post subject: | |||||
where piv is a value between 1 and 3 determining the location of the pivot (1 being the beginning, 2 being the middle and 3 being the end of the array)
I was supplied the original code for quicksort and partition, and instructed to code the rest to make it median of three quicksort (main declares the piv variable). The median calculation works fine, as does the switching. The problem is that the program takes about 7 seconds between printing the list (print_list function) and it does not sort it at all. Any ideas where the error is? Any help is greatly appreciated! |