标签:link 技术分享 add binary name list void else out
泛型类声明:
class 名称<泛型列表>
创建链表
LinkedList<String> mylist=new LinkedList<String>();
向链表增加节点
list.add(E obj);
从链表中删除节点
list.remove(index)
int binarySearch(List
import java.util.*;
public class StackPrint {
public static void main(String[] args) {
Stack<Integer> numberline=new Stack<Integer>();
int count = Integer.parseInt(args[0]);
int temp,add1,add2;
numberline.push(3);
numberline.push(8);
System.out.println("输出这个系列的前" + count + "个数:\n"+3+"\n"+8);
for (int i = 0; i < count; i++) {
add2 = numberline.pop();
add1 = numberline.pop();
temp = 2*(add1 + add2);
numberline.push(add1);
numberline.push(add2);
numberline.push(temp);
System.out.println(""+temp);
}
}
}
运行截图:
import java.util.*;
class Student implements Comparable {
int english=0;
String name;
Student(int english,String name) {
this.name=name;
this.english=english;
}
public int compareTo(Object b) {
Student st=(Student)b;
return (this.english-st.english);
}
}
public class EnglishGrades {
public static void main(String args[]) {
List<Student> list=new LinkedList<Student>();
int score []={50,94,37,79,84};
String name[]={"苏祚堃","朱越","张三","李四","王五"};
for(int i=0;i<score.length;i++){
list.add(new Student(score[i],name[i]));
}
Iterator<Student> iter=list.iterator();
TreeSet<Student> mytree=new TreeSet<Student>();
while(iter.hasNext()){
Student stu=iter.next();
mytree.add(stu);
}
Iterator<Student> te=mytree.iterator();
System.out.println("按成绩从小往大排:");
while(te.hasNext()) {
Student stu=te.next();
System.out.println(""+stu.name+" "+stu.english);
}
}
}
运行截图:
import java.util.*;
class UDiscKey implements Comparable {
double key=0;
UDiscKey(double d) {
key=d;
}
public int compareTo(Object b) {
UDiscKey disc=(UDiscKey)b;
if((this.key-disc.key)==0)
return -1;
else
return (int)((this.key-disc.key)*1000);
}
}
class UDisc{
int amount;
double price;
UDisc(int m,double e) {
amount=m;
price=e;
}
}
public class usbInformation {
public static void main(String args[ ]) {
TreeMap<UDiscKey,UDisc> treemap= new TreeMap<UDiscKey,UDisc>();
int amount[]={1,2,4,8,16};
double price[]={867,266,390,556};
UDisc UDisc[]=new UDisc[4];
UDiscKey key[]=new UDiscKey[4] ;
for(int k=0;k<UDisc.length;k++) {
UDisc[k]=new UDisc(amount[k],price[k]);
key[k]=new UDiscKey(UDisc[k].amount);
treemap.put(key[k],UDisc[k]);
}
Collection<UDisc> collection=treemap.values();
Iterator<UDisc> iter=collection.iterator();
while(iter.hasNext()) {
UDisc disc=iter.next();
System.out.println(""+disc.amount+"G "+disc.price+"?");
}
}
}
运行截图:
标签:link 技术分享 add binary name list void else out
原文地址:https://www.cnblogs.com/cloud795/p/8995007.html