Как из cписка организованного как очереди сделать кольцевой?
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#define LMES 100
typedef struct inform {
int index;
char message[LMES];
} INFORM;
typedef struct list_elem {
INFORM inform;
struct list_elem* next;
} LEL;
void MakeList(void);
LEL* AddElem(LEL* last);
void PrintList(void);
void FreeList(void);
LEL* list;
void main(){
MakeList();
PrintList();
FreeList();
}
void MakeList(void)
{
puts("\n Вхідні дані (для завершення індекс - 0):\n");
LEL* end = NULL;
do
end = AddElem(end);
while (end != NULL);
}
LEL* AddElem(LEL* last)
{
LEL* pel;
static int num = 1;
pel = (LEL*)malloc(sizeof(LEL));
if (pel == NULL)
{
puts("\n Немає більше вільної пам\'яті...\n Формування списку завершено.");
free(pel);
return NULL;
}
printf("\n %d елемент: індекс - ", num);
scanf_s("%d", &pel->inform.index);
if (pel->inform.index == 0) {
free(pel);
return NULL;
}
rewind(stdin);
printf("Повідомлення: ");
gets_s(pel->inform.message);
pel->next = NULL;
if (list == NULL)
list = pel;
else
last->next = pel;
num++;
return pel;
}
void PrintList(void)
{
LEL* pel = list;
puts("\n\n\t Сформований список:\n");
while (pel != NULL) {
printf("%10d\t%-70s\n", pel->inform.index, pel->inform.message);
pel = pel->next;
}
}
void FreeList(void)
{
LEL* pel = list;
while (pel != NULL) {
list = list->next;
free(pel);
pel = list;
}
}
Можно ли из cписка организованного как очереди сделать кольцевой?
Если можно то как?