order_by_int renamed to order_by_num + some experiments with lists
authorxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Sun, 5 Oct 2008 15:05:56 +0000 (15:05 +0000)
committerxchaos <xchaos@4bb87942-c103-4e5a-b51c-0ebff58f8515>
Sun, 5 Oct 2008 15:05:56 +0000 (15:05 +0000)
git-svn-id: https://dev.arachne.cz/repos/cll1h/trunk@97 4bb87942-c103-4e5a-b51c-0ebff58f8515

cll1.h
demos/ansi-c/float-list-plain-c.c [new file with mode: 0644]
demos/lists.c [deleted file]
demos/lists/cll1.h [new symlink]
demos/lists/float-list-ordered.c [new file with mode: 0644]
demos/lists/float-list-plain.c [new file with mode: 0644]
demos/lists/lists.c [new file with mode: 0644]

diff --git a/cll1.h b/cll1.h
index a3a6a317773105dca4fd3e15b3163ac757104fd4..f6f023576409e9ffce435fefc502f6c749a152de 100644 (file)
--- 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) (K1<K2)
+#define order_by_num(K1,K2) (K1>K2)
+#define order_by_num_desc(K1,K2) (K1<K2)
 #define order_by_str(K1,K2) (str_order(K1,K2)>0)
 #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 (file)
index 0000000..0501873
--- /dev/null
@@ -0,0 +1,60 @@
+#include <stdio.h>\r
+#include <stdlib.h>\r
+\r
+\r
+struct Node \r
+{\r
+        float f;\r
+        struct Node* next;\r
+};\r
+\r
+void IterateList (struct Node* HeadList);\r
+struct Node* makelist(struct Node** Head, struct Node** Tail);\r
+\r
+struct Node* makelist(struct Node** Head, struct Node** Tail)\r
+{\r
+        struct Node* new = (struct Node *)malloc(sizeof (struct Node));\r
+        new->next = NULL;\r
+\r
+        if (*Head == NULL)\r
+        {\r
+                *Head = new;\r
+                *Tail = *Head;\r
+        }\r
+        else\r
+        {\r
+                (*Tail)->next = new;\r
+                *Tail = new;\r
+        }\r
+        return (new);\r
+}\r
+void IterateList (struct Node* HeadList)\r
+{\r
+        struct Node* current = HeadList;\r
+\r
+        while (current != NULL)\r
+        {\r
+                printf("The float you entered is %f\n",current->f);\r
+                current = current->next;\r
+        }\r
+}\r
+int main(void)\r
+{\r
+        struct Node* head = NULL;\r
+        struct Node* tail = NULL;\r
+        struct Node* curr = NULL;\r
+        int i;\r
+\r
+        for(i=0; i < 20; i++)\r
+        {\r
+                /* create node */\r
+                curr = makelist(&head,&tail);\r
+                printf("Enter float :\n");\r
+                scanf("%f", &(curr->f));\r
+        }\r
+\r
+        /* now iterate the list */\r
+        IterateList(head);\r
+\r
+        return 0;\r
+}\r
diff --git a/demos/lists.c b/demos/lists.c
deleted file mode 100644 (file)
index 81eddae..0000000
+++ /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 (symlink)
index 0000000..a4cde1a
--- /dev/null
@@ -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 (file)
index 0000000..a9c996f
--- /dev/null
@@ -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 (file)
index 0000000..808303f
--- /dev/null
@@ -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 (file)
index 0000000..9af730e
--- /dev/null
@@ -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);
+ }
+}
This page took 0.235344 seconds and 4 git commands to generate.