欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

通過數(shù)據(jù)結構實現(xiàn)簡易通訊錄

AddressBookTest 是測試類

成都創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:網(wǎng)站建設、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務,滿足客戶于互聯(lián)網(wǎng)時代的平陸網(wǎng)站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡建設合作伙伴!

package MyADB;import java.util.InputMismatchException;

import java.util.Scanner;class InstructionsMistake extends Exception {

public InstructionsMistake(String mo) {

super(mo);

public class AddressBookTest {

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

MyAddressBook AdB = new MyAddressBook();

Scanner rb = new Scanner(System.in);

String name = new String();

String cell = new String();

boolean isNum = false;

int co = 0;

System.out.println("******** 簡易通訊錄管理程序 ********");

System.out.println(" 1. 插入新的聯(lián)系人    ");

System.out.println(" 2. 查詢已有聯(lián)系人    ");

System.out.println(" 3. 更改已有聯(lián)系人    ");

System.out.println(" 4. 刪除已有聯(lián)系人    ");

System.out.println(" 5. 顯示已有聯(lián)系人    ");

System.out.println(" 6. 退出通訊錄程序    ");

do {

System.out.print("\n******** 請輸入你所要操作的代碼 :");

try {

co = rb.nextInt();

} catch (InputMismatchException e) {

throw new InstructionsMistake(" 輸入的操作代碼有誤 ");

}  

if (co == 1) {

System.out.print(" 請輸入新的聯(lián)系人姓名 :");

name = rb.next();

System.out.print(" 請輸入新的聯(lián)系人手機號碼 :");

cell = rb.next();

// 運用正則表達式對手機號碼的輸入進行規(guī)范

isNum = cell.matches("^1[3|5|7|8]\\d{9}$");

while (!isNum) {

System.out.print(" 輸入的手機號碼有誤,請重新輸入 :");

cell = rb.next();

isNum = cell.matches("^1[3|5|7|8]\\d{9}$");

}

AdB.addAdB(name, cell);

System.out.println(" 聯(lián)系人 " + name + " 成功錄入 ");

} else if (co == 2) {

System.out.print(" 請輸入所查詢的聯(lián)系人姓名 :");

name = rb.next();

String str = AdB.searchAdB(name);

if (str == null) {

System.out.println(" 找不到 " + name + " 聯(lián)系人 ");

} else {

System.out.println(" 查找成功 ");

System.out.println(" 該聯(lián)系人的手機號碼為 :" + str);

}

} else if (co == 3) {

System.out.print(" 請輸入要更改的聯(lián)系人姓名 :");

name = rb.next();

String str = AdB.searchAdB(name);

if (str == null) {

System.out.println(" 找不到 " + name + " 聯(lián)系人 ");

} else {

System.out.println("1/ 更改聯(lián)系人的姓名 ");

System.out.println("2/ 更改聯(lián)系人的手機號碼 ");

System.out.print(" 請輸入操作代碼 :");

int cot = rb.nextInt();

if (cot == 1) {

System.out.print(" 請輸入該聯(lián)系人的新姓名 :");

String toName = rb.next();

toName = AdB.ChangeAdBName(name,toName);

System.out.println(" 該聯(lián)系人姓名成功更改為 :" + toName);

} else if (cot == 2) {

System.out.print(" 請輸入該聯(lián)系人的新手機號碼 :");

String toCell = rb.next();

isNum = toCell.matches("^1[3|5|7|8]\\d{9}$");

while (!isNum) {

System.out.print(" 輸入的手機號碼有誤,請重新輸入 :");

toCell = rb.next();

isNum = toCell.matches("^1[3|5|7|8]\\d{9}$");

}

toCell = AdB.ChangeAdBCell(name,toCell);

System.out.println(" 該聯(lián)系人手機號碼成功更改為 :" + toCell)

} else if (co == 4) {

System.out.print(" 輸入要刪除的聯(lián)系人姓名 :");

name = rb.next();

AdB.deleteAdB(name);

} else if (co == 5) {

System.out.println(AdB);

} else if (co == 6){

break;

}

} while (co != 6);

System.out.println("******** 成功退出通訊錄程序 ********");

MyAddressBook 類

package MyADB;

// 雙向

public class MyAddressBook {// 通訊錄

protected Node first;// 第一個聯(lián)系人 ( 通訊錄的管理工具 )

protected Node last;// 最后一個聯(lián)系人

protected int size = 0;// 聯(lián)系人的個數(shù)

// 通訊錄中的單個聯(lián)系人

protected class Node {// 聯(lián)系人 ( 內(nèi)部類 )

Node prev;// 上一個聯(lián)系人

Node next;// 下一個聯(lián)系人

public String name;// 姓名

public String cell;// 手機號碼

public Node(String name, String call) {

this.name = name;

this.cell = call;

// 尾插法

public void addAdB(String name, String call) {

Node node = new Node(name, call);// 新建一個聯(lián)系人

if (size == 0) {

this.first = node;

this.last = node;

} else {

// 把新增聯(lián)系人作為之前最后的聯(lián)系人的下一個

this.last.next = node;

// 把最后一個聯(lián)系人作為新增聯(lián)系人的上一個聯(lián)系人

node.prev = this.last;

// 把新增聯(lián)系人作為通訊錄的最后一個

this.last = node;

}size++;

}// 查找聯(lián)系人

public String searchAdB(String name) {

if (size == 0) {

System.out.println(" 通訊錄為空 ");

return null;

}Node current = this.first;

for (int i = 0; i < size; i++) {

if (!current.name.equals(name)) {

if (current.next == null) {

// 找不到返回空

return null;

current = current.next;

// 找到后返回該聯(lián)系人的手機號碼

return current.cell;

}// 返回聯(lián)系人自身

public Node retuName(String name) {

if (size == 0) {

System.out.println(" 通訊錄為空 ");

return null;

}Node current = this.first;

for (int i = 0; i < size; i++) {

if (!current.name.equals(name)) {

current = current.next;

return current;

// 更改聯(lián)系人姓名

public String ChangeAdBName(String name, String toName) {

Node current = retuName(name);

current.name = toName;

return current.name;

}// 更改聯(lián)系人手機號碼

public String ChangeAdBCell(String name, String toCell) {

Node current = retuName(name);

current.cell = toCell;

return current.cell;

}// 刪除指定聯(lián)系人

public void deleteAdB(String name) {

if (size == 0) {

System.out.println(" 通訊錄為空 ");

return;

}// 找到被刪除的聯(lián)系人

Node current = this.first;

for (int i = 0; i < size; i++) {

if (!current.name.equals(name)) {

if (current.next == null) {

System.out.println(" 找不到 " + name + " 聯(lián)系人 ");

return;

current = current.next;

// 進行刪除操作

if (current == first) {// 刪除通訊錄中頂部的一個聯(lián)系人

this.first = current.next;

this.first.prev = null;

} else if (current == last) {// 刪除通訊錄中最底部的一個聯(lián)系人

this.last = current.prev;// 將該聯(lián)系人的上一個聯(lián)系人作為通訊錄的最后一個聯(lián)系人

this.last.next = null;// 最后一個聯(lián)系人對下一個聯(lián)系人引用為空

} else // 將該聯(lián)系人的下一個聯(lián)系人作為該聯(lián)系人的上一個聯(lián)系人的 next

current.next英鎊符號https://www.gendan5.com/currency/GBP.html

current.prev.next = current.next; // 將該聯(lián)系人的上一個聯(lián)系人作為該聯(lián)系人的下一個聯(lián)系人的 prev

current.next.prev = current.prev; }size--; System.out.println(" 已將 " + name + " 移除通訊錄 ");

}public String toString() {

if (size == 0) {

return " 通訊錄為空 ";

}// 拼接字符串

StringBuilder sbBuilder = new StringBuilder(size * 2 + 1);

Node current = this.first;

int counet = 0;

while (current != null) {

sbBuilder.append(" 聯(lián)系人姓名為 :" + current.name + "\n");

sbBuilder.append(" 該聯(lián)系人手機號碼為 :" + current.cell + "\n");

if (counet != size - 1) {

sbBuilder.append("\n");

counet++;

}current = current.next;

}return sbBuilder.toString();

文章名稱:通過數(shù)據(jù)結構實現(xiàn)簡易通訊錄
URL鏈接:http://aaarwkj.com/article38/jeecpp.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設計公司、網(wǎng)站內(nèi)鏈、移動網(wǎng)站建設、網(wǎng)站建設、服務器托管搜索引擎優(yōu)化

廣告

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

外貿(mào)網(wǎng)站建設
午夜福利视频欧美成人| 91日本视频在线播放| 中国一级黄片免费欧美| av免费观看日韩永久| 性生活自制视频网站麻豆| 亚洲综合偷拍欧美一区日韩| 国产三级av高清一区二区| 日本三卡=卡无人区| 亚洲女人下体毛茸茸视频| 亚洲天堂福利视频网站| 日本在线免费高清观看| 亚洲国产精品有码专区| 日韩中文字幕视频一区| 国产精品兄妹在线观看91| 日韩精品视频一区二区在线观看 | 亚洲精品不卡在线观看| 欧美精品一区二区三区狠狠| 日本精品国产一区二区在线| 日韩一区二区三级电影| 国产一区二区高清在线| 国产一区二区不卡自拍| 日韩 在线一区二区| 日韩一区二区三区av| 人妻av一区二区三区| av天堂精品一区二区三区| 精品一区二区视频在线观看网站| 99精品国产一区二区青青性色| 精品亚洲在线一区二区| 成年网站在线91九色| 精品人妻中文字幕在线| 久久青草视频在线观看| 欧美亚洲另类激情另类的| 日本待黄大片一区二区| 久久热久久热在线视频| 亚洲精品成人中文字幕| 91白丝视频在线观看| 欧美亚洲午夜一二综合| 91久久精品中文字幕| 成人性生活毛片免费视频| 国产午夜激情在线播放| 中文字幕人妻熟女人妻|