This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinked-list.gql
59 lines (52 loc) · 1.65 KB
/
linked-list.gql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
############################################# SCHEMA #############################################
define
node sub entity,
has data,
plays head,
plays previous,
plays next;
linked-list sub entity,
plays list;
node-connection sub relation,
relates list,
relates head,
relates previous,
relates next;
data sub attribute, datatype string;
############################################# DATA #############################################
insert
$bob isa node, has data "Bob";
$sam isa node, has data "Sam";
$jessica isa node, has data "Jessica";
$eric isa node, has data "Eric";
$alexis isa node, has data "Alexis";
$l isa linked-list;
(list: $l, head: $bob, next: $sam) isa node-connection;
(list: $l, previous: $sam, next: $jessica) isa node-connection;
(list: $l, previous: $jessica, next: $eric) isa node-connection;
(list: $l, previous: $eric, next: $alexis) isa node-connection;
############################################# QUERY #############################################
#Who is in queue before Alexis?
match
$l isa linked-list;
$alexis isa node, has data "Alexis";
(list: $l, $x, next: $alexis) isa node-connection;
$x has data $x_data;
get $x_data;
#Who is in queue after the person after Bob?
match
$l isa linked-list;
$bob isa node, has data "Bob";
(list: $l, $bob, next: $afterBob) isa node-connection;
(previous: $afterBob, next: $x) isa node-connection;
$x has data $x_data;
get $x_data;
#Who is the last person in the queue?
match
$l isa linked-list;
$lastNode isa node, has data $lastNode_data;
(list: $l, next: $lastNode) isa node-connection;
not {
(previous: $lastNode, next: $x) isa node-connection;
};
get $lastNode_data;