成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

java數(shù)據(jù)結(jié)構(gòu)實現(xiàn)代碼 java數(shù)據(jù)結(jié)構(gòu)實現(xiàn)代碼是什么

用java實現(xiàn)一個數(shù)據(jù)結(jié)構(gòu)!

import java.io.IOException;

目前創(chuàng)新互聯(lián)公司已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間綿陽服務(wù)器托管、企業(yè)網(wǎng)站設(shè)計、鹿城網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

import java.util.Scanner;

public class LinkList {

private static Scanner san = new Scanner(System.in);

public static void main(String[] args) throws IOException {

List list = new List();

for (int i = 1; i = 10; i++) {

System.out.print("請輸入第" + i + "個數(shù): ");

list.add(san.nextInt());

list.print();

}

System.out.println("輸入的數(shù)據(jù)如下: ");

list.print();

}

}

class node {

int data;

node next = this; // 指向自己

}

class List {

private node header = new node();

// 循環(huán)鏈表的尾部添加數(shù)據(jù)

public node add(int data) {

node current = new node();

node temp = header;

while (temp.next != header)

temp = temp.next;

current.data = data;

current.next = temp.next;

temp.next = current;

return current;

}

// 查詢某個數(shù)字的位置 如果不在 返回-1;

public int search(int data) {

node temp = header;

int n = 0;

while (temp.next != header) {

temp = temp.next;

n++;

if (temp.data == data)

break;

}

if (temp.data == data)

return n;

else

return -1;

}

// 打印出整個鏈表

public void print() {

node temp = header;

while (temp.next != header) {

temp = temp.next;

System.out.print(temp.data + " ");

}

System.out.println();

}

// 插入數(shù)據(jù)

public node Insert(int pos, int data) {

node temp = header;

node current = new node();

for (int i = 0; i pos - 1; i++) {

if (temp.next != header) {

temp = temp.next;

} else

return null;

}

current.data = data;

if (temp.next != header) {

current.next = temp.next;

}

temp.next = current;

return current;

}

// 刪除某個數(shù)據(jù)

public node del(int data) {

node temp = header;

node oldtemp = null;

node current = null;

while (temp.next != header) {

oldtemp = temp;

temp = temp.next;

if (temp.data == data) {

current = temp;

break;

}

}

if (current == header)

return null;

oldtemp.next = current.next;

return current;

}

}

關(guān)于數(shù)據(jù)結(jié)構(gòu)(java)的一個代碼

描述棧抽象數(shù)據(jù)類型的SStack接口的聲明

public interfaceSStackE //棧接口

{

boolean isEmpty(); //判斷是否空棧,若空棧返回true

boolean push(E element); //元素element入棧,若操作成功返回true

E pop(); //出棧,返回當(dāng)前棧頂元素,若??辗祷豱ull

E get(); //取棧頂元素值,未出棧,若棧空返回null

}

順序棧類具體操作方法的聲明:

importdataStructure.linearList.SStack;

public classSeqStackE implements SStackE

//順序棧類

{

private Object value[]; //存儲棧的數(shù)據(jù)元素

private int top; //top為棧頂元素下標(biāo)

public SeqStack(int capacity) //構(gòu)造指定容量的空棧

{

this.value = newObject[Math.abs(capacity)];

this.top=-1;

}

public SeqStack() //構(gòu)造默認(rèn)容量的空棧

{

this(10);

}

public boolean isEmpty() //判斷是否空棧,若空棧返回true

{

return this.top==-1;

}

public boolean push(E element) //元素element入棧,若操作成功返回true

{

if (element==null)

return false; //空對象(null)不能入棧

if (this.top==value.length-1) //若棧滿,則擴充容量

{

Object[] temp = this.value;

this.value = newObject[temp.length*2];

for (int i=0; itemp.length;i++)

this.value[i] = temp[i];

}

this.top++;

this.value[this.top] = element;

return true;

}

public E pop() //出棧,返回當(dāng)前棧頂元素,若棧空返回null

{

if (!isEmpty())

return (E)this.value[this.top--];

else

return null;

}

public E get() //取棧頂元素值,未出棧,棧頂元素未改變

{

if (!isEmpty())

return (E)this.value[this.top];

else

return null;

}

public String toString() //返回棧中各元素的字符串描述

{

String str="{";

if (this.top!=-1)

str +=this.value[this.top].toString();

for (int i=this.top-1; i=0; i--)

str += ","+this.value[i].toString();

return str+"} ";

}

實例引用public static void main(String args[])

{

SeqStackString stack = newSeqStackString(20);

System.out.print("Push: ");

char ch='a';

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

{

String str =(char)(ch+i)+"";

stack.push(str);

System.out.print(str+" ");

}

System.out.println("\n"+stack.toString());

System.out.print("Pop : ");

while(!stack.isEmpty()) //全部出棧

System.out.print(stack.pop().toString()+" ");

System.out.println();

}

用Java語言編寫數(shù)據(jù)結(jié)構(gòu)中順序表的插入刪除查找代碼并實現(xiàn)

public class Test {

public static void main(String[] args) {

int length = 5;

int ai = 1;

String data = "data";

String[] array = insertArrar(data, ai, length);

data = delArray(array, ai, length);

System.out.println(data);

}

public static String[] insertArrar(String data,int ai,int length){

String[] array = new String[length];

array[ai] = data;

return array;

}

public static String delArray(String[] array,int ai,int length){

String data = "";

data=array[ai];

array[ai]=null;

for(int i = 0; iarray.length;i++){

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

}

return data;

}

}

本文題目:java數(shù)據(jù)結(jié)構(gòu)實現(xiàn)代碼 java數(shù)據(jù)結(jié)構(gòu)實現(xiàn)代碼是什么
網(wǎng)頁路徑:http://jinyejixie.com/article32/hepipc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供移動網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、網(wǎng)站設(shè)計公司網(wǎng)站內(nèi)鏈、網(wǎng)站改版、用戶體驗

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化
鹰潭市| 韩城市| 全州县| 嘉兴市| 安庆市| 高碑店市| 石城县| 钟山县| 绵竹市| 冕宁县| 武汉市| 靖西县| 修武县| 福泉市| 新昌县| 康乐县| 梅河口市| 奉化市| 于都县| 泾源县| 金溪县| 房产| 邵东县| 白银市| 唐河县| 太和县| 恩施市| 连城县| 万州区| 观塘区| 文山县| 彭州市| 长沙县| 宁海县| 瑞安市| 旬邑县| 唐河县| 南投市| 南宁市| 阿瓦提县| 久治县|