📄 fflylist.java
字号:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
class InfoType {
private String hbh;
private String start;
private String end;
private String sche;
private String time1;
private String time2;
private String model;
private int price;
InfoType() {
}
InfoType(String a,String b,String c,String d,String e,String f,String g,int h) {
hbh=a;
start=b;
end=c;
sche=d;
time1=e;
time2=f;
model=g;
price=h;
}
String GetHbh() {
return(hbh);
}
String GetOne() {
return(hbh+"\t"+start+"\t"+end+"\t"+sche+"\t"+time1+"\t"+time2+"\t"+model+"\t"+price+"\n");
}
int compareToPrice(InfoType bb)
{
if(bb.price>price)
return(1);
else if(bb.price<price)
return(-1);
else
return(0);
}
int compareTo(String s,InfoType bb)
{
if(s.equals("hbh"))
return(hbh.compareTo(bb.hbh));
else if(s.equals("start"))
return(start.compareTo(bb.start));
else if(s.equals("end"))
return(end.compareTo(bb.end));
else if(s.equals("time1"))
return(time1.compareTo(bb.time1));
else if(s.equals("time2"))
return(time2.compareTo(bb.time2));
else if(s.equals("model"))
return(model.compareTo(bb.model));
else if(s.equals("price"))
return(compareToPrice(bb));
return(0);
}
boolean equals(String s,String bb)
{
if(s.equals("hbh"))
return(equalsHbh(bb));
else if(s.equals("start"))
return(equalsStart(bb));
else if(s.equals("end"))
return(equalsEnd(bb));
else if(s.equals("time1"))
return(equalsTime1(bb));
else if(s.equals("time2"))
return(equalsTime2(bb));
else if(s.equals("model"))
return(equalsModel(bb));
else if(s.equals("date"))
return(equalsDate(bb));
else if(s.equals("price"))
return(equalsPrice(bb));
return(true);
}
boolean equalsHbh(String s)
{
return(hbh.equals(s));
}
boolean equalsStart(String s)
{
return(start.equals(s));
}
boolean equalsEnd(String s)
{
return(end.equals(s));
}
boolean equalsTime1(String s)
{
return(time1.equals(s));
}
boolean equalsTime2(String s)
{
return(time2.equals(s));
}
boolean equalsModel(String s)
{
return(model.equals(s));
}
boolean equalsDate(String s)
{
Date aa=new Date();
int year=0,month=0,date=0;
try {
year=Integer.parseInt(s.substring(0,4))-1900;
month=Integer.parseInt(s.substring(4,6));
date=Integer.parseInt(s.substring(6,8));
System.out.println(date);
}
catch(Exception e)
{}
aa.setYear(year);
aa.setMonth(month);
aa.setDate(date);
int day=(aa.getDay()+7-2)%7;
day=(day==0)?7:day;
String sday=new Integer(day).toString();
if (sche.indexOf("每日")>=0)
return(true);
else if(sche.indexOf(sday)>=0)
return(true);
return(false);
}
boolean equalsPrice(String s)
{
int key=0;
try {
key=Integer.parseInt(s);
}
catch(Exception e)
{}
if(price==key)
return(true);
else
return(false);
}
}
class SLList {
static int MaxSpace=100;
InfoType sl[]=new InfoType[MaxSpace];
int length;
SLList() {
length=1;
}
void append(String a,String b,String c,String d,String e,String f,String g,int h) {
sl[length]=new InfoType(a,b,c,d,e,f,g,h);
length++;
}
void fileappend(String s) {
String h[]=new String[8];
for(int i=0;i<7;i++)
{
h[i]=s.substring(0,s.indexOf("|"));
s=s.substring(s.indexOf("|")+1);
}
h[7]=s;
append(h[0],h[1],h[2],h[3],h[4],h[5],h[6],Integer.parseInt(h[7]));
}
String GetTitle() {
return("航班号\t起点站\t终点站\t航班期\t起飞时间\t到达时间\t机型\t票价\n");
}
String GetTotal() {
String tt=GetTitle();
for(int i=1;i<length;i++)
tt+=sl[i].GetOne();
return tt;
}
void SortAbsInsert(String fun)
{
int i,j;
for(i=2;i<length;i++)
if(sl[i].compareTo(fun,sl[i-1])<0) {
sl[0]=sl[i];
j=i-1;
do{
sl[j+1]=sl[j];
j--;
}while(sl[0].compareTo(fun,sl[j])<0);
sl[j+1]=sl[0];
}
}
void SortShell(String fun)
{
for(int gap=length/2;gap>0;gap/=2)
for(int i=gap;i<length;i++)
{
InfoType tmp=sl[i];
int j=i;
for(;j>gap&&tmp.compareTo(fun,sl[j-gap])<0;j-=gap)
sl[j]=sl[j-gap];
sl[j]=tmp;
}
}
void SortBubble(String fun)
{
int i,j;
boolean exchange;
for(i=1;i<length; i++) {
exchange=false;
for(j=length-2;j>=i;j--)
if(sl[j+1].compareTo(fun, sl[j])<0) {
sl[0]=sl[j+1];
sl[j+1]=sl[j];
sl[j]=sl[0];
exchange=true;
}
if(!exchange)
break;
}
}
void SortByTree(String fun)
{
for( int i = length / 2; i >0; i-- )
percDown(fun, i, length );
for( int i = length-1; i > 0; i-- )
{
swapReferences( sl,0, i );
percDown(fun, 0, i );
}
}
int leftChild( int i )
{
return 2 * i + 1;
}
void percDown(String fun, int i, int n )
{
int child;
InfoType tmp;
for( tmp = sl[ i ]; leftChild( i ) < n; i = child )
{
child = leftChild( i );
if( child != n - 1 && sl[ child ].compareTo(fun, sl[ child + 1 ] ) < 0 )
child++;
if( tmp.compareTo(fun, sl[ child ] ) < 0 )
sl[ i ] = sl[ child ];
else
break;
}
sl[ i ] = tmp;
}
void SortMerge(String fun)
{
SortMerge(fun,1,length-1);
}
void SortMerge(String fun, int left, int right )
{
if( left < right )
{
int center = ( left + right ) / 2;
SortMerge(fun, left, center );
SortMerge(fun, center + 1, right );
merge(fun, left, center + 1, right );
}
}
void merge(String fun, int leftPos, int rightPos, int rightEnd )
{
int leftEnd = rightPos - 1;
int tmpPos = leftPos;
int numElements = rightEnd - leftPos + 1;
InfoType [ ] tmpArray = new InfoType[ sl.length ];
while( leftPos <= leftEnd && rightPos <= rightEnd )
if( sl[ leftPos ].compareTo(fun, sl[ rightPos ] ) <= 0 )
tmpArray[ tmpPos++ ] = sl[ leftPos++ ];
else
tmpArray[ tmpPos++ ] = sl[ rightPos++ ];
while( leftPos <= leftEnd )
tmpArray[ tmpPos++ ] = sl[ leftPos++ ];
while( rightPos <= rightEnd )
tmpArray[ tmpPos++ ] = sl[ rightPos++ ];
for( int i = 0; i < numElements; i++, rightEnd-- )
sl[ rightEnd ] = tmpArray[ rightEnd ];
}
private static final int CUTOFF = 3;
public static final void swapReferences(InfoType[ ]sl,int index1, int index2 )
{
InfoType tmp = sl[ index1 ];
sl[ index1 ] = sl[ index2 ];
sl[ index2 ] = tmp;
}
InfoType median3(String fun, int left, int right )
{
int center = ( left + right ) / 2;
if( sl[ center ].compareTo(fun, sl[ left ] ) < 0 )
swapReferences(sl,left, center );
if( sl[ right ].compareTo(fun, sl[ left ] ) < 0 )
swapReferences(sl, left, right );
if( sl[ right ].compareTo(fun, sl[ center ] ) < 0 )
swapReferences( sl, center, right );
swapReferences(sl, center, right - 1 );
return sl[ right - 1 ];
}
void SortQuick(String fun)
{
SortQuick(fun, 1, length-1);
}
void SortQuick(String fun, int left, int right )
{
if( left + CUTOFF <= right )
{
InfoType pivot = median3(fun, left, right );
int i = left, j = right - 1;
for( ; ; )
{
while( sl[ ++i ].compareTo(fun, pivot ) < 0 ) { }
while( sl[ --j ].compareTo(fun, pivot ) > 0 ) { }
if( i < j )
swapReferences( sl, i, j );
else
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -