java数据结构题目(java数据结构题目数组)

华为云服务器特价优惠火热进行中!

2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。

合作流程:
1、点击链接注册/关联华为云账号:点击跳转
2、添加客服微信号:cloud7591,确定产品方案、价格方案、服务支持方案等;
3、客服协助购买,并拉微信技术服务群,享受一对一免费技术支持服务;
技术专家在金蝶、华为、腾讯原厂有多年工作经验,并已从事云计算服务8年,可对域名、备案、网站搭建、系统部署、AI人工智能、云资源规划等上云常见问题提供更专业靠谱的服务,对相应产品提供更优惠的报价和方案,欢迎咨询。

本篇文章给大家谈谈java数据结构题目,以及java数据结构题目数组对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

微信号:cloud7591
如需了解更多,欢迎添加客服微信咨询。
复制微信号

本文目录一览:

用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数据结构编程题目

自己参考下吧,希望对你有用!

//用单链表来实现多项式的加法,代码如下

public class Polynomial {

private Monomial first; // 首项

// 添加单项式

public void append(Monomial monomial) {

if (monomial == null) {

// do nothing

} else if (first == null) {

first = monomial;

} else {

Monomial current = first;

while (current != null) {

// 提示:如果指数相同,则相加

if (current.index == monomial.index) {

current.coefficient += monomial.coefficient;

break;

} else if (current.next == null) { // 否则直接把此项扔到最后

current.next = monomial;

break;

}

current = current.next;

}

}

}

public void append(int c, int i) {

append(new Monomial(c, i));

}

public String toString() {//toString()方法就是把对象转换成String类型

//比如一个Integer对象的toString方法就是把这个对象表示的整数转化成字符串,133就成了"133"。

StringBuffer sb = new StringBuffer();

Monomial current = first;

while (current.next != null) {

sb.append("(" + current.coefficient + "x^" + current.index

+ ") + ");

current = current.next;

}

sb.append("(" + current.coefficient + "x^" + current.index + ")");

return sb.toString();

}

// 两个多项式相加

public Polynomial add(Polynomial p2) {

Polynomial result = new Polynomial();

Monomial current = this.first;

while (current != null) {

result.append(current.coefficient, current.index); // 提示:注意这里

current = current.next;

}

current = p2.first;

while (current != null) {

result.append(current.coefficient, current.index);

current = current.next;

}

return result;

}

public static void main(String[] args) {

//构造多项式p1的每一项

Polynomial p1 = new Polynomial();

p1.append(3, 4);

p1.append(-6, 2);

p1.append(5, 1);

p1.append(-10, 0);

System.out.println("p1: " + p1);

//构造多项式p2的每一项

Polynomial p2 = new Polynomial();

p2.append(2, 5);

p2.append(-6, 2);

p2.append(5, 1);

System.out.println("p2: " + p2);

Polynomial result = p1.add(p2);

System.out.println("p1+p2= " + result);

}

}

/**

* 这是一个内部类

* 单项式的表示

*/

class Monomial {

int coefficient; // 系数

int index; // 指数

Monomial next; // 后继结点

public Monomial() {

}

public Monomial(int c, int i) {

this.coefficient = c;

this.index = i;

}

}

设计一个有序顺序表 数据结构(java)

package array;

class OrderArray{

private long[] a;

private int nElems;

public OrderArray(int maxSize){

a = new long[maxSize];

nElems = 0;

}

public void insert(long value){

int pos = 0;

for(pos=0;posnElems;pos++){

if(a[pos]value){

break;

}

}

for(int i=nElems;ipos;i--){

a[i] = a[i-1];

}

a[pos] = value;

nElems++;

}

public boolean delete(long value){

int pos = find(value);

if(pos!=-1){

for(int i=pos;inElems;i++){

a[i] = a[i+1];

}

nElems --;

return true;

}

return false;

}

public int find(long keySearch){

int lowerBound = 0;

int upperBound = nElems-1;

int curIn = 0;

while(true){

curIn = (lowerBound+upperBound)/2;

if(a[curIn]==keySearch){

return curIn;

}else if(lowerBoundupperBound){

return -1;

}else{

if(a[curIn]keySearch){

upperBound = curIn -1;

}else{

lowerBound = curIn +1;

}

}

}

}

public void display(){

for(int i=0;inElems;i++){

System.out.println(a[i]);

}

}

}

public class OrderArrayApp {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

int maxSize = 100;

OrderArray orderArray = new OrderArray(maxSize);

orderArray.insert(1);

orderArray.insert(7);

orderArray.insert(9);

orderArray.insert(8);

orderArray.insert(6);

orderArray.insert(4);

orderArray.display();

orderArray.delete(8);

orderArray.display();

}

}

求一些JAVA数据结构的试题及答案解析

1 下列数据结构中,能用二分法进行查找的是__A____。

A、顺序存储的有序线性表 B、线性链表 C、二叉链表 D、有序线性链表 解析:二分法查找只适用于顺序存储的有序表。在此所说的有序表是指线性表中的元素按值非递减排列(即从小到大,但允许相邻元素值相等)。 2 在软件设计中,不属于过程设计工具的是__D____。 A、PDL(过程设计语言) B、PAD图 C、N-S图 D、DFD图 解析:软件设计工具包括:程序流程图、N-S、PAD、HIPO,判定表,PDL(伪码)。而DFD(数据流图)属于结构化分析工具。

3 在switch(expression)语句中,expression的数据类型不能是__A____。 A、double B、char C、byte D、short

解析:表达式expression只能返回这个几种类型的值:int、byte、short和char。多分支语句把表达式返回的值依次与每个case子句中的值相比较,如果遇到匹配的值,则执行该case子句后的语句序列。

4 下列叙述中,错误的是__D____。

A、父类不能替代子类 B、子类能够替代父类 C、子类继承父类 D、父类包含子类 5 通过继承实现代码复用:

Java中所有的类都是通过直接或间接地继承java.lang.Object类得到的。继承而得到的类称为子类,被继承的类称为父类。子类不能继承父类中访问权限为private的成员变量和方法,子类可以重写父类的方法,及命名与父类同名的成员变量。 子类通过隐藏父类的成员变量和重写父类的方法,把父类的状态和行为改变为自身的状态和行为。注意:子类中重写的方法和父类中被重写的方法要具有相同的名字,相同的参数表和相同的返回类型,只是函数体不同。

由于子类继承了父类所有的属性(私有的除外),所以子类对象可以作为父类对象使用。程序中凡是使用父类对象的地方,都可以用子类对象来代替。一个对象可以通过引用子类的实例来调用子类的方法。

java运行时系统根据调用该方法的实例,来决定调用哪个方法。对子类的一个实例,如果子类重写了父类的方法,则运行时系统调用子类的方法;如果子类继承了父类的方法(未重写),则运行时系统调用父类的方法。

6 自定义表格类中的model部分应实现的接口是___A___。

A、AbstractTableModel B、JTable C、TableModel D、TableModelable 7 下列代码中,将引起编译错误的行是__B____。 1)public class Exercise{

2) public static void main(String args[]){ 3) float f=0.0; 4) f+=1.0; 5) } 6) }

A、第2行 B、第3行 C、第4行 D、第6行

解析:float定义变量赋值时,需要在数值后面加f以标识它为浮点型,让系统知道该给它精确到多少位。

关于java数据结构题目和java数据结构题目数组的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

发布于 2023-04-12 01:04:01
收藏
分享
海报
18
目录

    忘记密码?

    图形验证码

    复制成功
    微信号: cloud7591
    如需了解更多,欢迎添加客服微信咨询。
    我知道了