Update of /cvsroot/anet/ANet/ANet_Daemon/Common/Lists/samples
In directory usw-pr-cvs1:/tmp/cvs-serv15972/ANet_Daemon/Common/Lists/samples
Added Files:
sample.c
Log Message:
""
--- NEW FILE: sample.c ---
/*
Benad's linked lists.
Simple, fast linked lists.
That's it.
WARNING: Using a broken linked list with any of those functions may crash
your computer, and/or do something crazy with it. I tested my functions
enough to know that if that happens, it's not MY fault...
*/
#include <stdio.h>
#include <stdlib.h>
#include "LinkedLists.h"
UInt8 SimpleDestructor(NodePtr theNode);
UInt8 SimpleIsWhatIWant(NodePtr theNode);
SInt8 SimpleCompare(NodePtr a, NodePtr b);
int main(int argc, char **argv)
{
DoubleNodePtr a, b, c, list;
/*NodePtr found;*/
/*BinaryNodePtr binaryTree, newVal;*/
UInt32 nbr;
a = malloc(sizeof(DoubleNode));
b = malloc(sizeof(DoubleNode));
c = malloc(sizeof(DoubleNode));
a->next = b;
a->prev = NULL;
b->next = c;
b->prev = NULL;
c->next = NULL;
c->prev = NULL;
list = a;
nbr = NbrNodes((NodePtr)(a));
SplitAndMergeSort((NodePtr*)(&list), SimpleCompare);
/*FillPrev(list);*/
/*binaryTree = SortedDoubleToBinary(list);*/
/*newVal = malloc(sizeof(BinaryNode));
newVal->left = newVal->right = (BinaryNodePtr)(0);
InsertInTree(newVal, &binaryTree, SimpleCompare);*/
BalanceTree((BinaryNodePtr*)(&list)); /*List is like fully unbalanced tree*/
/*if (SplitAtNth(a, 2) != c)
return 1;*/
/*if (GetNthNode(a, 2) != c)
return 1;
found = FindAndMoveOut(&a, SimpleIsWhatIWant);
nbr = NbrNodes(found);
if (DestroyLinkedList(found, SimpleDestructor) != nbr)
/* ACK! Error! */
/* return 1;*/
/*InvertList(&list);*/
/*SplitAndMergeSort(&(NodePtr)(list), SimpleCompare);*/
/*InvertDoubleList(&list);*/
return 0;
}
UInt8 SimpleDestructor(NodePtr theNode)
{
free(theNode);
return (!theNode);
}
UInt8 SimpleIsWhatIWant(NodePtr theNode)
{
return (UInt8)(theNode);
}
SInt8 SimpleCompare(NodePtr a, NodePtr b)
{
return (a-b);
}
|