#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef int64_t s64;
typedef int64_t s32;
typedef int64_t s16;
typedef int64_t s8;
typedef uint64_t u64;
typedef uint64_t u32;
typedef uint64_t u16;
typedef uint64_t u8;
//#define forLL1(LoopOnLink) \
//for(link *CurrentLink = (LoopOnLink).Next, *StartLink = &(LoopOnLink); \
// CurrentLink != StartLink; \
// CurrentLink = CurrentLink->Next)
// type ??
#define forDL(StructName, LoopOnLink, NextName) \
for(struct{ \
s64 i; \
link *Start; \
link *Current; \
}StructName = { \
0, \
&(LoopOnLink), \
&(LoopOnLink) \
}; \
StructName.i == 0 || StructName.Current != StructName.Start; \
StructName.Current = StructName.Current->NextName, ++StructName.i)
#define forSL(StructName, LoopOnLink) f
struct link{
link *Next;
link *Prev;
s64 Var;
};
void LinkInit(link *CurrentLink, s64 NewLinkVariable)
{
CurrentLink->Next = CurrentLink;
CurrentLink->Prev = CurrentLink;
CurrentLink->Var = NewLinkVariable;
}
void LinkAddAfter(link *PrevLink, link *CurrentLink, s64 NewLinkVariable)
{
CurrentLink->Var = NewLinkVariable;
CurrentLink->Next = PrevLink->Next;
CurrentLink->Prev = PrevLink;
PrevLink->Next->Prev = CurrentLink;
PrevLink->Next = CurrentLink;
}
void LinkAdd(link *NextLink, link *CurrentLink, s64 NewLinkVariable)
{
CurrentLink->Var = NewLinkVariable;
CurrentLink->Prev = NextLink->Prev;
CurrentLink->Next = NextLink;
NextLink->Prev->Next = CurrentLink;
NextLink->Prev = CurrentLink;
}
// Linked list array.
struct link_array{
link_array *Next;
s64 Var;
};
struct link_array_head{
link_array *Next;
link_array *Last;
s64 Count;
};
void LinkArrayInit(link_array_head *LinkHead)
{
LinkHead->Next = 0;
LinkHead->Last = (link_array *)LinkHead;
LinkHead->Count = 0;
}
void LinkArrayAdd(link_array_head *LinkHead, link_array *Link, s64 Var)
{
LinkHead->Last->Next = Link;
LinkHead->Last = Link;
LinkHead->Count++;
Link->Next = 0;
Link->Var = Var;
}
int main()
{
link a[73];
LinkInit(&a[0], -7);
LinkAdd(&a[0], &a[1], 65);
LinkAdd(&a[0], &a[2], 321);
LinkAdd(&a[0], &a[3], 98321);
LinkAddAfter(&a[1], &a[4], 31);
forDL(Link, a[2], Prev)
{
printf("%li, %li\n", Link.i, Link.Current->Var);
}
return 0;
}