Witam
Próbuję zaimplementować kolejkę w liście. Póki co zakładam że lista będzie jednoelementowa, a w tym jednym elemencie będzie znajdować się kolejka trójelementowa. Każdy element kolejki zawiera zmienne X,Y,Z. Program kompiluje się bez błędów, ale niestety kiedy próbuję go odpalić zawiesza się. Być może coś źle połączyłem wskaźnikami ? Niestety nie mogę znaleźć błędu, a nigdy wcześniej nie robiłem kolejki w liście, więc nie widziałem żadnego sposobu implementacji. Serdecznie proszę o pomoc :) Mój przykładowy program:
#include<stdio.h>
#include<stdlib.h>
struct fifo_node
{
int X;
int Y;
int Z;
struct fifo_node *next;
};
struct fifo_pointers
{
struct fifo_node *head, *tail;
};
struct list_node
{
int data;
struct fifo_pointers *container;
struct list_node *previous, *next;
};
struct list_node *create_list(int number,struct fifo_pointers *fifo)
{
struct list_node *first_node = (struct list_node *)malloc(sizeof(struct list_node));
int i;
if(first_node)
{
first_node->data = number;
for(i = 0;i<3;i++)
{
struct fifo_node *new_node = (struct fifo_node *)malloc(sizeof(struct fifo_node));
if(new_node)
{
new_node->X = i;
new_node->Y = i;
new_node->Z = i;
new_node->next = NULL;
if(fifo->head==NULL)
{
fifo->head = fifo->tail = new_node;
first_node->container->head = fifo->head;
}
else
{
fifo->tail->next=new_node;
fifo->tail=new_node;
first_node->container->tail = fifo->tail;
}
}
else
fprintf(stderr,"Nowy element nie został utworzony!\n");
}
first_node->previous = first_node->next = NULL;
}
return first_node;
}
void print_list_in_both_directions(struct list_node *list_pointer)
{
struct list_node *backward_pointer = NULL;
while(list_pointer) {
backward_pointer = list_pointer;
printf("%d ",list_pointer->data);
list_pointer = list_pointer->next;
}
puts("");
while(backward_pointer) {
printf("%d ",backward_pointer->data);
backward_pointer = backward_pointer->previous;
}
puts("");
}
int main(void)
{
struct list_node *list_pointer = NULL;
struct fifo_pointers fifo = {NULL,NULL};
list_pointer = create_list(0,&fifo);
print_list_in_both_directions(list_pointer);
return 0;
}