/* 2: Node n=new Node(1); 3: n.next=null,也就是n.next=head */ digraph demo { rankdir=LR; node [shape=record]; h [shape=ellipse]; n [shape=ellipse];
a [label="{1|null}" color="red"]; h -> null; n ->a; }
接下来把这个新创建的直接的地址赋值给头指针h:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/* 2: n=new Node(1); 3: n.next=null,也就是n.next=head 新创建的节点的地址赋值给头指针h 4: h=n; */ digraph demo { rankdir=LR node [shape=record] null h [shape=ellipse] n [shape=ellipse] a [label="{1|null}"] // h -> null n -> a h -> a [color="red"] }
然后,再次创建一个新的节点,地址赋值给引用变量n
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* 再次创建一个节点,并把地址赋值给指针n 5: n=new Node(2); */ digraph demo { rankdir=LR node [shape=record] h [shape=ellipse] n [shape=ellipse] n1 [label="{1|null}"] n2 [label="{2|}"] // null [shape=ellipse] // h -> null n -> n2 [color="red"] h -> n1 }
新创建的节点的地址域记录下链表的头节点的地址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* 把头指针h中保存的地址赋值给新创建的节点的地址域 6: n.next=head; */ digraph demo { rankdir=LR node [shape=record] h [shape=ellipse] n [shape=ellipse] n1 [label="{1|null}"] n2 [label="{2|}"]
n -> n2 n2 -> n1 [color="red"] h -> n1 }
头指针记录新创建的节点的地址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 把头指针h中保存的地址赋值给新创建的节点的地址域 6: n.next=head 头指针保存新创建的节点的地址 7: h=n; */ digraph demo { rankdir=LR node [shape=record] h [shape=ellipse] n [shape=ellipse]
select sno,sum(score) as total_score from cs groupby sno;
(36)查询每个学生及其选修课程的情况。
1 2 3
select sno,sname,cno from student as s,cs where s.sno=cs.sno;
1 2 3 4
select sno,sname,cno,cname from student as s,cs,course as c where s.sno=cs.sno and cs.cno=c.cno;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
select sno,sname,cno,cname from (select sno,sname from student) as R1 innerjoin ( select sno,cno,cname from( (select cno,cname from course) as C innerjoin (select sno,cno from cs) as cs2 on c.cno=cs2.cno ) ) as R2 on R1.sno=R2.sno;
select s.sno,sanme,cname,score from student as s,cs,course as c where s.sno=cs.sno and cs.cno=c.cno;
1 2 3 4 5 6 7 8 9 10 11
select sno,sname,cname,score from ( select sno,sname from student ) as R1, ( select sno,cname,score from cs,course as c where cs.cno=s.cno ) as R2 where R1.sno=R2.sno;
1 2 3 4 5 6
select s1.sno,sname,c1.cname,score from (select sno,sname from student) as s1, (select cno,cname from course) as c1, cs where s1.sno=cs.sno and cs.cno=c1.cno;
select sno from cs where not exists( select cno from cs as where not exists( select from cs where sno=’95002’ and ; ) )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
selectdistinct x.sno -- 对于学生x from sc as x -- 不存在 wherenotexists( select* from sc as y -- 这样一门课, 95002选了,x没有选 where y.sno ='95002'andnotexists( select* from sc as z -- 课程 y, x没选 where z.cno = y.cno and z.sno = x.sno ) ); ;