Hello,
I'm trying to implment a qeueue using dynamic data structures. The code compiles and all, but the problem is that the pointer that is supposed to point to the head of the qeueue keeps on pointing to the end of the qeueue.... here's part of the code..
oh yeah, ptr1 and ptr2 are declared in main and are initialized as NULL
Code:
struct data_node {
double price_1;
struct data_node *nextptr;
};
typedef struct data_node Data_1;
typedef Data_1 *Data_1ptr;
void Get( Data data_2[], int size, Data_1ptr *headptr, Data_1ptr *tailptr, int a, int b)
{
int ctr =0;
Data_1ptr newptr;
newptr = malloc(sizeof(Data_1));
for ( ctr = a; ctr <= b; ctr++) {
if ( newptr != NULL ) {
newptr->price_1 = data_2[ctr].price;
newptr->nextptr = NULL;
if ( *headptr==NULL ) {
*headptr = newptr; }
else {
(*tailptr)->nextptr = newptr; }
*tailptr = newptr;
printf("headptr %10.2f tailptr %10.2f\n", (*headptr)->price_1, (*tailptr)->price_1);
}
else {
printf(" No memory available.\n");
}
}