Java设计线性表排序算法import java.util.Scanner;
import java.util.Arrays;
public class P
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
float[] A=new float[1],B=new float[1];
int alen=0,blen=0,i,j,k;
String line;
System.out.println("请输入线性表A的各元素,每行一个(输入#结束):");
while(true)
{
line=sc.nextLine();
if(line.equals("#"))
break;
A=Arrays.copyOf(A,++alen);
A[alen-1]=Float.parseFloat(line);
}
System.out.println("请输入线性表B的各元素,每行一个(输入#结束):");
while(true)
{
line=sc.nextLine();
if(line.equals("#"))
break;
B=Arrays.copyOf(B,++blen);
B[blen-1]=Float.parseFloat(line);
}
Arrays.sort(A);
Arrays.sort(B);
System.out.println("升序排序后,线性表A的各元素是:");
for(i=0;ialen;i++)
{
System.out.print(A[i]+" ");
}
System.out.println();
System.out.println();
System.out.println("升序排序后,线性表B的各元素是:");
for(i=0;iblen;i++)
{
System.out.print(B[i]+" ");
}
System.out.println();
System.out.println();
A=Arrays.copyOf(A,alen+blen);
for(i=0;iblen;i++)
{
if(B[i]=A[alen-1])
A[alen++]=B[i];
else
{
for(j=0;jalen-1;j++)
{
if(B[i]=A[j])
break;
}
for(k=alen-1;k=j;k--)
{
A[k+1]=A[k];
}
A[j]=B[i];
alen++;
}
}
System.out.println("线性表B按顺序插入线性表A中后,线性表A的各元素是:");
for(i=0;ialen;i++)
{
System.out.print(A[i]+" ");
}
sc.close();
}
}
java关于线性表的编程package Test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringBufferInputStream;
import java.io.StringReader;
import java.util.Scanner;
class Test {
private static Node firstList, secondList, resultList;
private static void input(Node head) throws Exception {
int a;
int b;
int i;
Node p = head;
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
// 读取一行信息
String input = reader.readLine();
// 以空格为分隔符Java线性表代码,转换成数组
String[] numbers = input.split(" ");
for(i=0;inumbers.length;){
a = Integer.parseInt(numbers[i]);
b = Integer.parseInt(numbers[i+1]);
p.next = new Node(a, b);
p = p.next;
i+=2;
}
}
public static void main(String[] args) throws Exception {
firstList = new Node();
secondList = new Node();
resultList = new Node();
Node p=resultList;
System.out.println("输入第一个多项式");
input(firstList);
System.out.println("输入第二个不等式");
input(secondList);
while(firstList.next!=nullsecondList.next!=null){
if(firstList.next.zssecondList.next.zs){
p.next=new Node(firstList.next.xs,firstList.next.zs);
p=p.next;
firstList=firstList.next;
}else if(firstList.next.zssecondList.next.zs){
p.next=new Node(secondList.next.xs,secondList.next.zs);
p=p.next;
secondList=secondList.next;
}else{
p.next=new Node(firstList.next.xs+secondList.next.xs,firstList.next.zs);
p=p.next;
firstList=firstList.next;
secondList=secondList.next;
}
}
if(firstList!=null){
p.next=firstList.next;
}
if(secondList!=null){
推荐阅读
- 集体视频号起名怎么起,个人视频号名称怎么取名比较好
- 新媒体是如何改变商业的,新媒体是如何改变商业的
- ppt太大了怎么转pdf,ppt 太大
- jsp中java代码块,jsp java代码
- 登录的函数python python登录程序代码
- iosgba4ios怎么下游戏下载游戏,苹果4s怎么下载b站
- 精灵射击的街机游戏名字,精灵射击的街机游戏名字叫什么
- 快手李北音直播回放,李北音资料
- 关于vb.net号意思的信息