From ea514b9e6351878fef9638813f50ce7013e8a832 Mon Sep 17 00:00:00 2001 From: xchaos Date: Sun, 5 Oct 2008 15:05:56 +0000 Subject: [PATCH] order_by_int renamed to order_by_num + some experiments with lists git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@97 4bb87942-c103-4e5a-b51c-0ebff58f8515 --- cll1.h | 4 +- demos/ansi-c/float-list-plain-c.c | 60 +++++++++++++++++++ demos/lists.c | 91 ----------------------------- demos/lists/cll1.h | 1 + demos/lists/float-list-ordered.c | 25 ++++++++ demos/lists/float-list-plain.c | 29 ++++++++++ demos/lists/lists.c | 95 +++++++++++++++++++++++++++++++ 7 files changed, 212 insertions(+), 93 deletions(-) create mode 100644 demos/ansi-c/float-list-plain-c.c delete mode 100644 demos/lists.c create mode 120000 demos/lists/cll1.h create mode 100644 demos/lists/float-list-ordered.c create mode 100644 demos/lists/float-list-plain.c create mode 100644 demos/lists/lists.c diff --git a/cll1.h b/cll1.h index a3a6a31..f6f0235 100644 --- a/cll1.h +++ b/cll1.h @@ -141,8 +141,8 @@ extern unsigned RANDOM_SEED; //to do: seek //to do: store #define count(NODE,HEAD,VAR) { _NEW(I,0) for(NODE=HEAD; NODE || ((VAR=_I),0) ; (NODE=NODE->__next)?(_I++):0 ); } -#define order_by_int(K1,K2) (K1>K2) -#define order_by_int_desc(K1,K2) (K1K2) +#define order_by_num_desc(K1,K2) (K10) #define order_by_str_desc(K1,K2) (str_order(K1,K2)<0) #define order_by_ascii(K1,K2) (str_ascii(K1,K2)>0) diff --git a/demos/ansi-c/float-list-plain-c.c b/demos/ansi-c/float-list-plain-c.c new file mode 100644 index 0000000..0501873 --- /dev/null +++ b/demos/ansi-c/float-list-plain-c.c @@ -0,0 +1,60 @@ +#include +#include + + +struct Node +{ + float f; + struct Node* next; +}; + +void IterateList (struct Node* HeadList); +struct Node* makelist(struct Node** Head, struct Node** Tail); + +struct Node* makelist(struct Node** Head, struct Node** Tail) +{ + struct Node* new = (struct Node *)malloc(sizeof (struct Node)); + new->next = NULL; + + if (*Head == NULL) + { + *Head = new; + *Tail = *Head; + } + else + { + (*Tail)->next = new; + *Tail = new; + } + return (new); +} +void IterateList (struct Node* HeadList) +{ + struct Node* current = HeadList; + + while (current != NULL) + { + printf("The float you entered is %f\n",current->f); + current = current->next; + } +} +int main(void) +{ + struct Node* head = NULL; + struct Node* tail = NULL; + struct Node* curr = NULL; + int i; + + for(i=0; i < 20; i++) + { + /* create node */ + curr = makelist(&head,&tail); + printf("Enter float :\n"); + scanf("%f", &(curr->f)); + } + + /* now iterate the list */ + IterateList(head); + + return 0; +} diff --git a/demos/lists.c b/demos/lists.c deleted file mode 100644 index 81eddae..0000000 --- a/demos/lists.c +++ /dev/null @@ -1,91 +0,0 @@ -#include "cll1.h" - -def_mem(Record) -{ - int i; - str s; - list(Record); -}; - -program -{ - Record record, records=NULL; - - print("4x insert(record,records,order_by_int,i);"); - - record=get_mem(Record); - record->i=1; - record->s="ddd"; - insert(record,records,order_by_int,i); - - record=get_mem(Record); - record->i=3; - record->s="BBBB"; - insert(record,records,order_by_int,i); - - record=get_mem(Record); - record->i=4; - record->s="e"; - insert(record,records,order_by_int,i); - - record=get_mem(Record); - record->i=2; - record->s="aaaa"; - insert(record,records,order_by_int,i); - - for_each(record,records) - { - printf("i=%d, s=%s\n",record->i,record->s); - } - - print("1x append(record,records);"); - record=get_mem(Record); - record->i=0; - record->s="ccc"; - append(record,records); - - for_each(record,records) - { - printf("i=%d, s=%s\n",record->i,record->s); - } - - print("sort(record,records,order_by_int_desc,i);"); - sort(record,records,order_by_int_desc,i); - - for_each(record,records) - { - printf("i=%d, s=%s\n",record->i,record->s); - } - - print("sort(record,records,order_by_str,s);"); - sort(record,records,order_by_str,s); - - for_each(record,records) - { - printf("i=%d, s=%s\n",record->i,record->s); - } - - print("sort(record,records,order_by_ascii_desc,s);"); - sort(record,records,order_by_ascii_desc,s); - - for_each(record,records) - { - printf("i=%d, s=%s\n",record->i,record->s); - } - - print("remove(record,records,record->i==1);"); - remove(record,records,record->i==1); - - for_each(record,records) - { - printf("i=%d, s=%s\n",record->i,record->s); - } - - print("drop(record,records);"); - drop(record,records); - - for_each(record,records) - { - printf("i=%d, s=%s\n",record->i,record->s); - } -} diff --git a/demos/lists/cll1.h b/demos/lists/cll1.h new file mode 120000 index 0000000..a4cde1a --- /dev/null +++ b/demos/lists/cll1.h @@ -0,0 +1 @@ +../cll1.h \ No newline at end of file diff --git a/demos/lists/float-list-ordered.c b/demos/lists/float-list-ordered.c new file mode 100644 index 0000000..a9c996f --- /dev/null +++ b/demos/lists/float-list-ordered.c @@ -0,0 +1,25 @@ +#include "cll1.h" + +def_mem(Node) +{ + float f; + list(Node); +}; + +program +{ + Node one,all=NULL; + + repeat(20) + { + one=get_mem(Node); + printf("Enter float: \n"); + scanf("%f", &(one->f)); + insert(one,all,order_by_num,f); + } + + for_each(one,all) + { + printf("The float you entered is %f\n",one->f); + } +} diff --git a/demos/lists/float-list-plain.c b/demos/lists/float-list-plain.c new file mode 100644 index 0000000..808303f --- /dev/null +++ b/demos/lists/float-list-plain.c @@ -0,0 +1,29 @@ +#include "cll1.h" + +def_mem(Node) +{ + float f; + list(Node); +}; + +program +{ + Node one,all=NULL,last=NULL; + + repeat(20) + { + one=get_mem(Node); + printf("Enter float: \n"); + scanf("%f", &(one->f)); + append(one,last); + if(not all) + { + all=last; + } + } + + for_each(one,all) + { + printf("The float you entered is %f\n",one->f); + } +} diff --git a/demos/lists/lists.c b/demos/lists/lists.c new file mode 100644 index 0000000..9af730e --- /dev/null +++ b/demos/lists/lists.c @@ -0,0 +1,95 @@ +#include "cll1.h" + +def_mem(Record) +{ + int i; + str s; + list(Record); +}; + +program +{ + Record record, records = NULL; + + print("4x insert(record,records,order_by_num,i);"); + + record = get_mem(Record); + record->i = 1; + record->s = "ddd"; + insert(record, records, order_by_num, i); + + record = get_mem(Record); + record->i = 3; + record->s = "BBBB"; + insert(record, records, order_by_num, i); + + record = get_mem(Record); + record->i = 4; + record->s = "e"; + insert(record, records, order_by_num, i); + + record = get_mem(Record); + record->i = 2; + record->s = "aaaa"; + insert(record, records, order_by_num, i); + + for_each(record, records) + { + printf("i=%d, s=%s\n", record->i, record->s); + } + + print("1x append(record,records);"); + + record = get_mem(Record); + record->i = 0; + record->s = "ccc"; + append(record, records); + + for_each(record, records) + { + printf("i=%d, s=%s\n", record->i, record->s); + } + + print("sort(record,records,order_by_num_desc,i);"); + + sort(record, records, order_by_num_desc, i); + + for_each(record, records) + { + printf("i=%d, s=%s\n", record->i, record->s); + } + + print("sort(record,records,order_by_str,s);"); + + sort(record, records, order_by_str, s); + + for_each(record, records) + { + printf("i=%d, s=%s\n",record->i,record->s); + } + + print("sort(record, records, order_by_ascii_desc, s);"); + + sort(record, records, order_by_ascii_desc, s); + + for_each(record,records) + { + printf("i=%d, s=%s\n", record->i, record->s); + } + + print("remove(record,records,record->i==1);"); + remove(record, records, record->i == 1); + + for_each(record,records) + { + printf("i=%d, s=%s\n", record->i, record->s); + } + + print("drop(record,records);"); + drop(record, records); + + for_each(record, records) + { + printf("i=%d, s=%s\n", record->i, record->s); + } +} -- 2.30.2