gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
mjc2wsl, typo
[mjc2wsl.git] / samples / linkedlist.mj
1 program linkedlist
2 class Element {
3 int info;
4 Element next;
5 }
6 Element first;
7 {
8 void add(int i)
9 Element newone;
10 {
11 newone = new Element;
12 newone.info = i;
13 newone.next = first;
14 first = newone;
15 }
17 void printlist()
18 Element cur;
19 {
20 cur = first;
21 while (cur != null) {
22 print(cur.info);
23 cur = cur.next;
24 }
25 }
27 int exists(int i) Element cur; {
28 cur = first;
29 while (cur != null && cur.info != i)
30 cur = cur.next;
31 if (cur != null)
32 return 1;
33 else
34 return 0;
35 }
37 int count(int i) Element cur; int c;{
38 cur = first;
39 c = 0;
40 while (cur != null) {
41 if (cur.info == i)
42 c++;
43 cur = cur.next;
44 }
45 return c;
46 }
48 void main()
49 int num; int in; int c; {
50 print('l');
51 print('?');
52 read(num);
53 // demo
54 if (num<0) {
55 add(1);
56 add(2);
57 add(3);
58 add(2);
59 printlist();
60 print(exists(7));
61 print(count(2));
62 } else {
63 c = 0;
64 while (c<num) {
65 print(c);
66 print('?');
67 read(in);
68 add(in);
69 c++;
70 }
71 printlist();
73 print('e');
74 print('?');
76 read(in);
77 print(exists(in));
79 print('c');
80 print('?');
81 read(in);
82 print(count(in));
83 }
84 }
85 }
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner