dp doubly linked list
This commit is contained in:
69
linkage.c
Normal file
69
linkage.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* IGC parser - data linking module (doubly linked datapoint list)
|
||||
* @brief parse IGC file, get all data points, compute average horizontal/vertical speed, print to STDOUT
|
||||
*
|
||||
* As per standard: https://xp-soaring.github.io/igc_file_format/igc_format_2008.html
|
||||
* https://xp-soaring.github.io/igc_file_format/igc_fr_specification_with_al8_2023-2-1_0.pdf
|
||||
*
|
||||
* @author xamidev <xamidev@riseup.net>
|
||||
* @license GNU GPL v3
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "igc.h"
|
||||
#include "linkage.h"
|
||||
|
||||
struct dp_node* create_datapoint_list()
|
||||
{
|
||||
struct dp_node* head = (struct dp_node*)calloc(1, sizeof(struct dp_node));
|
||||
|
||||
head->data = NULL;
|
||||
head->prev = NULL;
|
||||
head->next = NULL;
|
||||
return head;
|
||||
}
|
||||
|
||||
void append_datapoint(struct dp_node* list, struct IGC_DataPoint* dp)
|
||||
{
|
||||
struct dp_node* new = (struct dp_node*)calloc(1, sizeof(struct dp_node));
|
||||
|
||||
if (list->next == NULL)
|
||||
{
|
||||
list->next = new;
|
||||
|
||||
new->prev = list;
|
||||
new->next = NULL;
|
||||
new->data = dp;
|
||||
return;
|
||||
}
|
||||
|
||||
while (list->next != NULL)
|
||||
{
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
list->next = new;
|
||||
new->prev = list;
|
||||
new->next = NULL;
|
||||
new->data = dp;
|
||||
return;
|
||||
}
|
||||
|
||||
void print_datapoint_list(struct dp_node* list)
|
||||
{
|
||||
if (list->data == NULL)
|
||||
{
|
||||
// We're at head!
|
||||
list = list->next;
|
||||
}
|
||||
|
||||
while (list->next != NULL)
|
||||
{
|
||||
show_datapoint(list->data);
|
||||
printf(" <-> ");
|
||||
list = list->next;
|
||||
}
|
||||
puts("NULL");
|
||||
return;
|
||||
}
|
||||
Reference in New Issue
Block a user