「java数据结构题目」java数据结构期末考试题

博主:adminadmin 2022-11-29 02:31:08 50

今天给各位分享java数据结构题目的知识,其中也会对java数据结构期末考试题进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

用java编写一个数据结构的题!

线性表跟是不是数组没关系啊。。。栈和队列都是线性表吧。。不太懂你的意思。。

public class SeqList {

public static void main(String[] args) {

int[] a = new int[]{1,2,3,4,5,6,7};

int[] b = new int[]{3,5,8,9};

int[] c = new int[a.length + b.length];

new SeqList().seqListMerge(a, b, c);

}

public void seqListMerge(int[] a, int[] b, int[] c){

//i为数组a的计数器

int i = 0;

//j为数组b的计数器

int j = 0;

//k为数组c的计数器

int k = 0;

//判断两个数组长度,当一个先用完的时候推出循环

while(i a.length j b.length){

if(a[i] b[j]){

c[k] = b[j];

k++;

j++;

}else{

c[k] = a[i];

k++;

i++;

}

}

//如果a数组先到结尾,那么把b数组的剩下的值拼到c里

if( i == a.length){

while(j b.length){

c[k] = b[j];

k++;

j++;

}

}

//如果b数组先到结尾,那么把a数组的剩下的值拼到c里

if(j == b.length){

while(i a.length){

c[k] = a[i];

k++;

i++;

}

}

for(int p : c){

System.out.println(p);

}

}

}

java数据结构 题目:采用快速排序的前三趟结果 49 38 97 76 13 27 50

// quickSort1.java

////////////////////////////////////////////////////////////////

public class QuickSort1App

{

private long[] theArray;

private int nElems;

private int count=0; //记录输出三次

//--------------------------------------------------------------

public QuickSort1App(int max)

{

theArray = new long[max];

nElems = 0;

}

//--------------------------------------------------------------

public void insert(long value)

{

theArray[nElems] = value;

nElems++;

}

//--------------------------------------------------------------

public void display()

{

System.out.print("A=");

for(int j=0; jnElems; j++)

System.out.print(theArray[j] + " ");

System.out.println("");

}

//--------------------------------------------------------------

public void quickSort()

{

recQuickSort(0, nElems-1);

}

//--------------------------------------------------------------

public void recQuickSort(int left, int right)

{

if(right-left = 0)

return;

else

{

long pivot = theArray[right];

int partition = partitionIt(left, right, pivot);

recQuickSort(left, partition-1);

recQuickSort(partition+1, right);

}

}

//--------------------------------------------------------------

public int partitionIt(int left, int right, long pivot)

{

int leftPtr = left-1;

int rightPtr = right;

while(true)

{

while( theArray[++leftPtr] pivot );

while(rightPtr 0 theArray[--rightPtr] pivot); if(leftPtr = rightPtr)

break;

else

swap(leftPtr, rightPtr);

}

swap(leftPtr, right);

count++;

if(count=3){

display(); //记录输出三次

}

return leftPtr;

}

//--------------------------------------------------------------

public void swap(int dex1, int dex2)

{

long temp = theArray[dex1];

theArray[dex1] = theArray[dex2];

theArray[dex2] = temp;

}

public static void main(String[] args)

{

QuickSort1App arr;

arr = new QuickSort1App(7); arr.insert(49);

arr.insert(38);

arr.insert(97);

arr.insert(76);

arr.insert(13);

arr.insert(27);

arr.insert(50);

arr.quickSort();

}

//--------------------------------------------------------------

} // end class ArrayIns

////////////////////////////////////////////////////////////////

数据结构JAVA 版,比较两个顺序表相等。2-5题 不会!!!!(*・ω< )

顺序表element的数据结构是数组

判断数组是否相等不应该使用 == , 而是应该逐元素遍历判断相等

JDK提供了工具类Arrays.equals(arr1,arr2) 可以快速判断数组是否相等(内部就是循环遍历判断) 以int数组为例:

    public static boolean equals(int[] a, int[] a2) {

        if (a==a2)

            return true;

        if (a==null || a2==null)

            return false;

        int length = a.length;

        if (a2.length != length)

            return false;

        for (int i=0; ilength; i++)

            if (a[i] != a2[i])

                return false;

        return true;

    }

另: equals不是java的关键字, 只是Object对象的方法, 题干中方法明显是重写了equals方法,并没有错误

跪求Java数据结构排队就餐问题

经典的生产者消费者模式,网上百度一堆,两种方式,一种blockingqueue阻塞队列,一种逻辑实现

JAVA数据结构问题:在带头结点的单链表中,查找值为X的结点若找到则删除否则输出NO

你要是模拟的话,可以使用数组,查找每个值,存在就删除,不存在就输出No。你又不搞内部代码,模拟实现就可以了!

一道java数据结构题

public  class ComplexNumber {

private double imaginary;

private double real;

public ComplexNumber() {

}

public ComplexNumber(double real) {

this.real = real;

this.imaginary = 0;

}

public ComplexNumber(double real,double imaginary) {

this.real = real;

this.imaginary = imaginary;

}

public static ComplexNumber min(ComplexNumber c1,ComplexNumber c2){

return new ComplexNumber((c1.getReal()-c2.getReal()),(c1.getImaginary()-c2.getImaginary()));

}

public static ComplexNumber multiplication(ComplexNumber c1,ComplexNumber c2){

double r1 = c1.getReal();

double i1 = c1.getImaginary();

double r2 = c2.getReal();

double i2 = c2.getImaginary();

return new ComplexNumber((r1*r2-i1*i2),(r1*i2+r2*i1));

}

//set and get

public double getImaginary() {

return imaginary;

}

public void setImaginary(double imaginary) {

this.imaginary = imaginary;

}

public double getReal() {

return real;

}

public void setReal(double real) {

this.real = real;

}

}

main  function:

public class Main{

public static void main(String[] args) {

ComplexNumber c1 = ComplexNumber.min(new ComplexNumber(1, 1), new ComplexNumber(1, -1));

System.out.println(c1.getReal()+"+"+c1.getImaginary()+"i");

ComplexNumber c = ComplexNumber.multiplication(new ComplexNumber(1, 1), new ComplexNumber(1, -1));

System.out.println(c.getReal()+"+"+c.getImaginary()+"i");

}

}

java数据结构题目的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java数据结构期末考试题、java数据结构题目的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-29,除非注明,否则均为首码项目网原创文章,转载请注明出处。