Author |
Message |
Tubs

|
Posted: Thu Jan 26, 2006 11:52 pm Post subject: (No 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 |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tubs

|
Posted: Fri Jan 27, 2006 12:00 am Post subject: (No subject) |
|
|
This may be my tiredness / burntoutedness setting in, but I really really appreciate the help wtd. You're the man. |
|
|
|
|
 |
wtd
|
Posted: Fri Jan 27, 2006 3:12 pm Post subject: (No 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. |
|
|
|
|
 |
Tubs

|
Posted: Thu Feb 02, 2006 12:53 pm Post subject: (No 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 |
|
|
|
|
 |
wtd
|
Posted: Thu Feb 02, 2006 2:10 pm Post subject: (No subject) |
|
|
Generalize psuedocode for dealing with linked list iteration.
code: | set "current" to first node in list
while current node's not null do
access current node's stored value,
and ...
set "current" to the current node's pointer
to the next node
end while loop |
|
|
|
|
|
 |
Tubs

|
Posted: Thu Feb 02, 2006 3:11 pm Post subject: (No 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. |
|
|
|
|
 |
Andy
|
Posted: Thu Feb 02, 2006 3:32 pm Post subject: (No 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 |
|
|
|
|
 |
Tubs

|
Posted: Thu Feb 02, 2006 9:47 pm Post subject: (No 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?
code: | #include <stdio.h>
#ifndef INT_TYPES
#define INT_TYPES
#include <stdlib.h>
#include <stdio.h>
typedef struct
{
int value;
}
int_data_t;
typedef struct int_node
{
int_data_t data;
struct int_node *next;
}
int_node_t;
// Prototypes.
void create_int_list( int_node_t **, int );
int_node_t *insert_int_list( int_node_t **, int_data_t * );
void print_int_list( int_node_t * );
#endif
int main(int argc, char *argv[])
{
int_node_t *list;
int_data_t something;
something.value = 10;
*insert_int_list ( &list, &something);
create_int_list ( &list, something.value );
print_int_list ( list );
system("pause");
return 0;
}
void create_int_list( int_node_t **list, int n )
{
int i;
int_data_t temp;
for( i = n ; i >= 0 ; i-- )
{
// Insert the numbers in reverse order into the front of the list.
temp.value = i;
insert_int_list( list, &temp );
}
}
int_node_t *insert_int_list( int_node_t **list, int_data_t *data )
{
int_node_t *temp = NULL;
temp = (int_node_t *)malloc( sizeof( int_node_t ) );
if( temp != NULL )
{
temp->data = *data;
temp->next = *list;
*list = temp;
}
return temp;
}
void print_int_list( int_node_t *list )
{
int_node_t *current = list;
while( current != NULL )
{
printf( "%4d", current->data.value );
current = current->next;
}
printf( "\n" );
} |
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
wtd
|
Posted: Thu Feb 02, 2006 10:24 pm Post subject: (No subject) |
|
|
code: | typedef struct int_node
{
int_data_t data;
struct int_node *next;
}
int_node_t; |
This is one of the more inane things I've ever seen.
code: | int main(int argc, char *argv[])
{
int_node_t *list;
int_data_t something;
something.value = 10;
*insert_int_list ( &list, &something);
create_int_list ( &list, something.value );
print_int_list ( list );
system("pause");
return 0;
} |
Why are you dereferencing the return value of insert_int_list in a void context? |
|
|
|
|
 |
wtd
|
Posted: Thu Feb 02, 2006 10:25 pm Post subject: (No subject) |
|
|
wtd wrote: code: | typedef struct int_node
{
int_data_t data;
struct int_node *next;
}
int_node_t; |
This is one of the more inane things I've ever seen.
Errrr... I meant:
code: | typedef struct
{
int value;
}
int_data_t; |
|
|
|
|
|
 |
Tubs

|
Posted: Thu Feb 02, 2006 10:26 pm Post subject: (No subject) |
|
|
Yeah i was wondering about that as well. i guess its just to get us used to declaring the structure and stuff. |
|
|
|
|
 |
Tubs

|
Posted: Thu Feb 02, 2006 10:29 pm Post subject: (No subject) |
|
|
As for the dereferencing, I get the same error when i change it. |
|
|
|
|
 |
wtd
|
Posted: Thu Feb 02, 2006 10:30 pm Post subject: (No subject) |
|
|
An additional note is that you should not, by any means, be casting the return value of malloc. |
|
|
|
|
 |
wtd
|
Posted: Thu Feb 02, 2006 10:32 pm Post subject: (No 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. |
|
|
|
|
 |
Tubs

|
Posted: Thu Feb 02, 2006 10:38 pm Post subject: (No 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. |
|
|
|
|
 |
|