Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Why this dies
Index -> Programming, C++ -> C++ Help
Goto page Previous  1, 2, 3, 4  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tubs




PostPosted: 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 Sad

functions still to go:
- duplicate one node to another node
- duplicate a list to another list
- reverse a list
Sponsor
Sponsor
Sponsor
sponsor
Tubs




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 3 of 4  [ 52 Posts ]
Goto page Previous  1, 2, 3, 4  Next
Jump to:   


Style:  
Search: