Java线性表代码 线性表的定义和基本操作的代码实现

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){

推荐阅读