gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control system
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 19eee58)
raw | patch | inline | side by side (parent: 19eee58)
author | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 7 May 2016 14:08:01 +0000 (16:08 +0200) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 7 May 2016 14:08:44 +0000 (16:08 +0200) |
samples/linkedlist.mj | [new file with mode: 0644] | patch | blob |
tests/linkedlist.1.txt | [new file with mode: 0644] | patch | blob |
tests/linkedlist.2.txt | [new file with mode: 0644] | patch | blob |
tests/linkedlist.3.txt | [new file with mode: 0644] | patch | blob |
diff --git a/samples/linkedlist.mj b/samples/linkedlist.mj
--- /dev/null
+++ b/samples/linkedlist.mj
@@ -0,0 +1,85 @@
+program linkedlist
+ class Element {
+ int info;
+ Element next;
+ }
+ Element first;
+{
+ void add(int i)
+ Element newone;
+ {
+ newone = new Element;
+ newone.info = i;
+ newone.next = first;
+ first = newone;
+ }
+
+ void printlist()
+ Element cur;
+ {
+ cur = first;
+ while (cur != null) {
+ print(cur.info);
+ cur = cur.next;
+ }
+ }
+
+ int exists(int i) Element cur; {
+ cur = first;
+ while (cur != null && cur.info != i)
+ cur = cur.next;
+ if (cur != null)
+ return 1;
+ else
+ return 0;
+ }
+
+ int count(int i) Element cur; int c;{
+ cur = first;
+ c = 0;
+ while (cur != null) {
+ if (cur.info == i)
+ c++;
+ cur = cur.next;
+ }
+ return c;
+ }
+
+ void main()
+ int num; int in; int c; {
+ print('l');
+ print('?');
+ read(num);
+ // demo
+ if (num<0) {
+ add(1);
+ add(2);
+ add(3);
+ add(2);
+ printlist();
+ print(exists(7));
+ print(count(2));
+ } else {
+ c = 0;
+ while (c<num) {
+ print(c);
+ print('?');
+ read(in);
+ add(in);
+ c++;
+ }
+ printlist();
+
+ print('e');
+ print('?');
+
+ read(in);
+ print(exists(in));
+
+ print('c');
+ print('?');
+ read(in);
+ print(count(in));
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/linkedlist.1.txt b/tests/linkedlist.1.txt
--- /dev/null
+++ b/tests/linkedlist.1.txt
@@ -0,0 +1 @@
+-1
\ No newline at end of file
diff --git a/tests/linkedlist.2.txt b/tests/linkedlist.2.txt
--- /dev/null
+++ b/tests/linkedlist.2.txt
@@ -0,0 +1,7 @@
+4
+1
+2
+1
+4
+4
+1
diff --git a/tests/linkedlist.3.txt b/tests/linkedlist.3.txt
--- /dev/null
+++ b/tests/linkedlist.3.txt
@@ -0,0 +1,7 @@
+4
+1
+2
+3
+4
+5
+6