数据库对象练习
【HR/HR】
1、用学生选课场景创建表:
1.1
Student(id,sno,sname,telnum,email)
Course(id,cno,cname,teachername)
studentcourse(id,s_id,c_id)
-
CREATE TABLE student(
-
id NUMBER,
-
sno VARCHAR2 (15) NOT NULL,
-
sname VARCHAR2 (20) NOT NULL,
-
telnum VARCHAR2 (12),
-
email VARCHAR2 (50)
-
);
-
CREATE TABLE course(
-
id NUMBER,
-
cno VARCHAR2 (6) NOT NULL,
-
cname VARCHAR2 (30) NOT NULL,
-
teachername VARCHAR2(20)
-
);
-
CREATE TABLE studentcourse(
-
id NUMBER,
-
s_id NUMBER,
-
c_id NUMBER
-
);
SQL练习
【SCOTT/TIGER】
7. 用Decode函数实现横表和竖表的转换
-
SELECT deptno DEPARTMENT_ID,
-
COUNT(*) "部门人数",
-
SUM(DECODE(SIGN(sal-9000),-1,0,1)) "超高收入人数(>9000)",
-
SUM(DECODE(SIGN(sal-9000),-1,0,( DECODE(SIGN(sal-12000),1,0,1) ) )) "极高收入人数([9000,12000])",
-
SUM(DECODE(SIGN(sal-6000),-1,0,( DECODE(SIGN(sal-9000),1,0,1) ) )) "高收入([6000,9000])",
-
SUM(DECODE(SIGN(sal-3000),-1,0,( DECODE(SIGN(sal-6000),1,0,1) ) )) "一般收入([3000,6000])",
-
SUM(DECODE(SIGN(sal-3000),-1,1,0)) "低收入([<3000])"
-
FROM emp
-
GROUP BY deptno;
在redhat9.0下安装jdk和tomcat
==========================================
【安装JDK】
------------------------------------------
1. 下载一个bin的jdk
2. 丢到/opt目录下(一般来说放在这里?)
3. 进入目录,修改该文件的权限:
chmod a+x 文件名.bin
4. 运行该文件:
./文件名
# 于是它就自己安装了啊
# 等啊等 结束了
# 在opt目录下生成一个同名的文件夹
5. 打开etc/下的profile文件编辑
vi /etc/profile
6. 在文件最后加上
JAVA_HOME=/opt/文件夹名
CLASSPATH=$JAVA_HOME/jre/lib/rt.jar:.
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME CLASSPATH PATH
7. 使环境变量生效:
source /etc/profile
8. 测试:
java -version
求主元素的线性算法
知道怎么算,实现起来好囧,百度了一下,发现这个好简洁 = =,不过这个输入时就一定有主元素,故没有再对函数找出来的A[x]作判定:
基数排序实现
rt……
求亲密数对
= =
离散集合的find与union操作
@ _ @
-
#include<iostream>
-
using namespace std;
-
-
#define Type int
-
#define N 100
-
-
typedef struct Tree_node {
-
struct Tree_node* parent;
-
int rank;
-
Type value;
-
}NODE;
-
-
NODE* find(NODE *xp){
-
NODE *wp, *yp = xp, *zp = xp;
-
while(yp->parent){
-
yp = yp->parent;
-
}
-
while(zp->parent){
-
wp = zp->parent;
-
zp->parent = yp;
-
zp = wp;
-
}
-
return yp;
-
}
-
-
NODE* unionTree(NODE *xp, NODE *yp){
-
NODE *up, *vp;
-
up = find(xp);
-
vp = find(yp);
-
if(up->rank<=vp->rank){
-
up->parent = vp;
-
if(up->rank == vp->rank){
-
vp->rank ++;
-
}
-
up = vp;
-
}else{
-
vp->parent = up;
-
}
-
return up;
-
}
-
-
NODE* createNode(Type value, NODE* parent = NULL){
-
NODE* p = new NODE;
-
if(parent){
-
p->rank = parent->rank + 1;
-
}else{
-
p->rank = 1;
-
}
-
p->parent = parent;
-
p->value = value;
-
return p;
-
}
-
-
int main(){
-
NODE* A[N];
-
-
/* 建立集合{1,2,3,4} */
-
A[4] = createNode(4);
-
A[3] = createNode(3,A[4]);
-
A[2] = createNode(2,A[4]);
-
A[1] = createNode(1,A[2]);
-
-
-
-
/* 建立集合{5,6,7,8} */
-
A[8] = createNode(8);
-
A[7] = createNode(7,A[8]);
-
A[6] = createNode(6,A[8]);
-
A[5] = createNode(5,A[6]);
-
-
/* 合并两集合 */
-
unionTree(A[1],A[5]);
-
-
/* 遍历集合 */
-
for(int i = 1; i<=8; i++){
-
cout<<"结点"<<(A[i]->value)<<" ";
-
if(A[i]->parent)cout<<"父结点"<<(A[i]->parent->value);
-
else cout<<"该结点为根结点";
-
cout<<endl;
-
}
-
-
return 0;
-
}
合并堆算法
编写一个算法,把两个相同大小的堆合并成一个堆。
-
/*
-
* Title: 编写一个算法,把两个相同大小的堆,合并成一个堆。
-
* Author: YOYO
-
* Time: 2009-3-8
-
*
-
* 合并算法即其中的merge_heaps(Type A[], Type B[], Type C[], int n)
-
* 该算法将两个相同大小的堆A和B合并为一个大顶堆,并存储到C中。时间复杂度为O(n*log(n))
-
*
-
*/
-
#include<iostream>
-
using namespace std;
-
-
#define Type int
-
#define N 100
-
-
void shift_up(Type H[], int i);
-
void shift_down(Type H[], int n, int i);
-
void insert(Type H[], int &n, Type x);
-
void del(Type H[], int &n, int i);
-
Type delete_max(Type H[], int &n);
-
void print_heap(Type H[], int n);
-
void make_heap(Type H[], int n);
-
void heap_sort(Type H[], int n);
-
void merge_heaps(Type A[], Type B[], int n);
-
-
void shift_up(Type H[], int i){
-
bool done = false;
-
while(i!=1){
-
if(H[i]<=H[i/2]){
-
break;
-
}
-
swap(H[i], H[i/2]);
-
i /= 2;
-
}
-
}
-
-
void shift_down(Type H[], int n, int i){
-
bool done = false;
-
while( (i=2*i)<=n ){
-
if(i+1<=n&&H[i+1]>H[i]){
-
i ++;
-
}
-
if(H[i/2]>=H[i]){
-
break;
-
}
-
swap(H[i/2], H[i]);
-
}
-
}
-
-
void insert(Type H[], int &n, Type x){
-
n++;
-
H[n] = x;
-
shift_up(H,n);
-
}
-
-
void del(Type H[], int &n, int i){
-
Type x, y;
-
x = H[i], y = H[n];
-
n--;
-
if(i<=n){
-
H[i] = y;
-
if(y>=x){
-
shift_up(H,i);
-
}else{
-
shift_down(H,n,i);
-
}
-
}
-
}
-
-
Type delete_max(Type H[], int &n){
-
Type x = H[1];
-
del(H, n, 1);
-
return x;
-
}
-
-
void heap_sort(Type H[], int n){
-
make_heap(H,n);
-
for( int i = n; i>1; i--){
-
swap(H[1],H[i]);
-
shift_down(H,i-1,1);
-
}
-
}
-
-
void print_heap(Type H[], int n){
-
for( int i = 1, j = 1; i<=n; i++){
-
printf("%-4d",H[i]);
-
if((i+1)%j==0){
-
cout<<endl;
-
j*=2;
-
}
-
}
-
cout<<endl;
-
if(i%j)cout<<endl;
-
}
-
-
void make_heap(Type H[], int n){
-
H[n] = H[0];
-
for( int i= n/2; i>=1; i--){
-
shift_down(H,n,i);
-
}
-
}
-
-
/*
-
* 合并堆算法
-
*
-
* 输入:堆A,堆B,堆的长度n
-
* 输出:由堆A和堆B合并成的新大顶堆C
-
*
-
* 该算法执行了2n次时间复杂度为O(log(n))的insert操作,故
-
* 它的执行时间为O(n*log(n))
-
*
-
*/
-
void merge_heaps(Type A[], Type B[], Type C[], int n){
-
int i,k;
-
for(i=1, k = 0; i<=n; i++){
-
insert(C, k, A[i]);
-
}
-
for(i=1, k = n; i<=n; i++){
-
insert(C, k, B[i]);
-
}
-
}
-
-
int main(){
-
int i,n;
-
Type A[N],B[N],C[2*N];
-
-
/* 输入堆的元素 */
-
cout<<"请输入堆的元素个数:";
-
cin>>n;
-
-
cout<<"请输入堆A的元素:";
-
for(i = 0; i<n; i++){
-
cin>>A[i];
-
}
-
-
cout<<"请输入堆B的元素:";
-
for(i = 0; i<n; i++){
-
cin>>B[i];
-
}
-
-
/* 建堆 */
-
make_heap(A,n);
-
make_heap(B,n);
-
-
/* 打印堆*/
-
cout<<"大顶堆A:"<<endl;
-
print_heap(A,n);
-
-
cout<<"大顶堆B:"<<endl;
-
print_heap(B,n);
-
-
/* 合并堆 */
-
merge_heaps(A,B,C,n);
-
-
/* 打印堆*/
-
cout<<"合并后的大顶堆C:"<<endl;
-
print_heap(C,2*n);
-
-
return 0;
-
}