JAVA,希望高手可以给出源代码,我交作业用,不会做,非常感谢
请各位程序设计的高手们,请用java编程一下,非常感谢!!!!!!!!!!
这个用一个循环链表解决,代码如下,结果已验证正确,注释没时间写了,自己慢慢领会吧,我是大学生,也是个编程爱好者,有兴趣加QQ:568883776.希望能帮到你,对了,要记得给我分哈!!!(^o^)
class Node
{
int color;//0代表绿色1代表红色
Node next,brfore;
public Node(int n)
{
this.color=n;
}
}
class Chain//循环链表
{
Node head;
public void init_chain()
{
this.head=new Node(0);
Node p=head;
for(int i=1;i<=14;i++)
{
p.next=new Node(0);
p.next.brfore=p;
p=p.next;
}
p.next=head;
this.head.brfore=p;
}
}
public class Try
{
public static void main(String[] args)
{
int i,j;
Chain chain=new Chain();
chain.init_chain();
Node p=new Node(1);
p.next=chain.head.next;
chain.head.next.brfore=p;
p.brfore=chain.head;
chain.head.next=p;
Node pos=p;
for(i=1;i<=14;i++)
{
for(j=1;j<=13;j++)
pos=pos.brfore;
Node temp=new Node(1);
temp.next=pos.next;
pos.next.brfore=temp;
temp.brfore=pos;
pos.next=temp;
pos=temp;
}
for(j=1;j<=12;j++)
pos=pos.brfore;
for(i=1;i<=30;i++)
{
if(pos.color==0) System.out.print("绿");
else System.out.print("红");
pos=pos.next;
}
System.out.println();
}
}
结果:
绿绿绿绿绿红红红红绿绿红红绿红绿绿红绿红绿红红绿红红绿绿红红
上面的字串,第一个是开始位置,注意要头尾相接哈。
java练习题 请给出详细代码 谢啦
package myeclipse;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class StudentInfoInput {
private String stuNo;
private String stuName;
private double one;
private double two;
private double three;
private double four;
public StudentInfoInput() {
super();
// TODO Auto-generated constructor stub
}
public StudentInfoInput(String stuNo, String stuName) {
super();
this.stuNo = stuNo;
this.stuName = stuName;
}
public StudentInfoInput(String stuNo, String stuName, double one,
double two, double three, double four) {
super();
this.stuNo = stuNo;
this.stuName = stuName;
this.one = one;
this.two = two;
this.three = three;
this.four = four;
}
public StudentInfoInput(String stuName) {
super();
this.stuName = stuName;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public String getStuNo() {
return stuNo;
}
public void setStuNo(String stuNo) {
this.stuNo = stuNo;
}
public double getOne() {
return one;
}
public void setOne(double one) {
this.one = one;
}
public double getTwo() {
return two;
}
public void setTwo(double two) {
this.two = two;
}
public double getThree() {
return three;
}
public void setThree(double three) {
this.three = three;
}
public double getFour() {
return four;
}
public void setFour(double four) {
this.four = four;
}
public String toString() {
return "stuNo:"+stuNo+",stuName:"+stuName+",one:"+one+",two:"+two+",three:"+three+",four:"+four;
}
}
class Sort {
public static void main(String[] args) {
StudentInfoInput si1 = new StudentInfoInput("001","小明",23.2,123,65.3,98);
StudentInfoInput si2 = new StudentInfoInput("002","小红",54,54.5,78.7,43);
StudentInfoInput si3 = new StudentInfoInput("003","小小",56,34.5,67,90);
sort(si1,si2,si3);
}
public static void sort(StudentInfoInput si1,StudentInfoInput si2,StudentInfoInput si3) {
Map
ValueComparator vc = new ValueComparator(map);
TreeMap
map.put(si1, sum(si1));
map.put(si2, sum(si2));
map.put(si3, sum(si3));
tm.putAll(map);
System.out.println(tm);
}
public static double sum(StudentInfoInput si) {
return si.getOne()+si.getTwo()+si.getThree()+si.getFour();
}
}
class ValueComparator implements Comparator
Map
public ValueComparator(Map
this.base = base;
}
@Override
public int compare(StudentInfoInput o1, StudentInfoInput o2) {
if (base.get(o1) >= base.get(o2)) {
return -1;
} else {
return 1;
}
}
}