「java广义表」java表数范围

博主:adminadmin 2022-11-27 14:13:05 57

今天给各位分享java广义表的知识,其中也会对java表数范围进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

急!!请教JAVA怎样用广义表和凹入表表示二叉树、

凹入表

public void DisplayBinTree(BinTree T) {

BinTree p; BinTree[] stack = new BinTree[100]; int top, n, i; int[] level = new int[100]; if (T != null) { top = 1; stack[top] = T; level[top] = 3; while (top 0) { p = stack[top]; n = level[top]; for (i = 1; i = n; i++) System.out.print(" "); System.out.println(p.data); top--; if (p.rchild != null) { top++; stack[top] = p.rchild; level[top] = n + 3; } if (p.lchild != null) { top++; stack[top] = p.lchild; level[top] = n + 3; } } } }

广义表

public void ListBinTree(BinTree T) {

if (T!=null){ System.out.print(T.data); if (T.lchild!=null||T.rchild!=null){ System.out.print("("); ListBinTree(T.lchild); if (T.rchild!=null) System.out.print(","); ListBinTree(T.rchild); System.out.print(")"); } } }

求Java中比较两个广义表是否相等的代码模版

试编写判别两个广义表是否相等的递归算法。

广义表类型GList的定义:

[cpp]

view

plain

copy

typedef

enum

{ATOM,LIST}

ElemTag;

typedef

struct

GLNode{

ElemTag

tag;

union

{

char

atom;

struct

{

GLNode

*hp,

*tp;

}

ptr;

}un;

}

*GList;

实现的函数如下:

[cpp]

view

plain

copy

Status

Equal(GList

A,

GList

B)

/*

判断广义表A和B是否相等,是则返回TRUE,否则返回FALSE

*/

{

if(A

-

tag

==

ATOM

B

-

tag

==

ATOM){

//当都为原子节点ATOM时

if(A

-

un.atom

==

B

-

un.atom)

return

TRUE;

else

return

FALSE;

}else

if(A

-

tag

==

LIST

B

-

tag

==

LIST){

//当都为广义表节点LIST时

if(Equal(A

-

un.ptr.hp,B

-

un.ptr.hp)

Equal(A

-

un.ptr.tp,B

-

un.ptr.tp))

//递归判断表头节点是否相等,表尾节点是否相等

return

TRUE;

else

return

FALSE;

}

}

java中怎样用hashmap(或treemap)实现广义表

import java.util.*;

import static java.lang.System.out;

public class UseHashMap {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

test1();

test2();

test3();

}

static void test1(){

HashMap h1=new HashMap();

HashMap h2=new HashMap();

HashMap h3=new HashMap();

h2.put("A","B");

h1.put("", h2);

h3.put("C","D");

h1.put("A",h3);

out.println(h1.values());

}

static void test2(){

HashMap h1=new HashMap();

HashMap h2=new HashMap();

HashMap h3=new HashMap();

h2.put("", "B");

h1.put("",h2.values());

h3.put("C","D");

h1.put("A", h3);

out.println(h1.values());

}

static void test3(){

HashMap h1=new HashMap();

HashMap h2=new HashMap();

HashMap h3=new HashMap();

h2.put("B","C");

h3.put("A",h2);

h1.put("", h3);

out.println(h1.values());

}

}

哈哈。。。

Java广义表的建立代码模版。。。不要空白链表

java中的链表是指linkedList

看名字就能知道,它实现了List接口。

这就说明了,java中的链表首先是一个List,其次才是一个链表。

因此linkedList既有一个List具有的基本方法(能通过下标获取元素的get(index)方法),也有作为链表的方法(next()取得下一个元素)

综上所述,如果你想完全把这个对象作为链表使用,那就不用get下标方法就可以了。

java广义表的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java表数范围、java广义表的信息别忘了在本站进行查找喔。

The End

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