From fd7001c50d96864e0e83367bb6f845c1c24ff823 Mon Sep 17 00:00:00 2001 From: esoe Date: Tue, 25 Oct 2022 16:56:15 +0300 Subject: [PATCH] Pearl in work --- chain/src/main/java/ru/molokoin/App.java | 17 +++++++- chain/src/main/java/ru/molokoin/Pearl.java | 39 +++++++++++++++++-- chain/target/classes/ru/molokoin/App.class | Bin 889 -> 1381 bytes chain/target/classes/ru/molokoin/Pearl.class | Bin 1118 -> 1597 bytes 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/chain/src/main/java/ru/molokoin/App.java b/chain/src/main/java/ru/molokoin/App.java index b441d04..d214c13 100644 --- a/chain/src/main/java/ru/molokoin/App.java +++ b/chain/src/main/java/ru/molokoin/App.java @@ -6,6 +6,21 @@ public class App { int[] i = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; //Хранилище - Pearl treasury; + Pearl treasury = new Pearl(); + treasury.add(i[0]); + treasury.add(i[1]); + treasury.add(i[2]); + treasury.add(i[3]); + treasury.add(i[4]); + treasury.add(i[5]); + treasury.add(i[6]); + treasury.add(i[7]); + treasury.add(i[8]); + treasury.add(i[9]); + //печать из хранилища + treasury.print(); + System.out.print("Последний элемент списка: "); + treasury.getLast().print(); + } } diff --git a/chain/src/main/java/ru/molokoin/Pearl.java b/chain/src/main/java/ru/molokoin/Pearl.java index 65dad83..a5a02c7 100644 --- a/chain/src/main/java/ru/molokoin/Pearl.java +++ b/chain/src/main/java/ru/molokoin/Pearl.java @@ -9,16 +9,49 @@ package ru.molokoin; */ public class Pearl { private Object gem; - private Pearl next = null; + private Pearl next; + public Pearl(){ + this(null, null); + } public Pearl(Object gem){ + this(gem, null); + } + public Pearl(Object gem, Pearl next){ setGem(gem); + setNext(next); } + /** + * Рекурсивно печатает данные, пока не упрется в next = null + */ public void print(){ - System.out.println((int)gem); + System.out.println(gem); + if (next != null){ + getNext().print(); + } } + /** + * перебирает жемчужины до конца, последней присваивет в next новую жемчужину + * @param gem + */ public void add(Object gem){ - next.setGem(gem); + if(this.gem == null){setGem(gem);} + else { + Pearl pearl = new Pearl(gem); + Pearl current = this; + while (current.next != null){ + current = current.next; + } + current.next = pearl; + } + } + + public Pearl getLast(){ + Pearl current = this; + while (current.next != null){ + current = current.next; + } + return current; } /** * @param gem the gem to set diff --git a/chain/target/classes/ru/molokoin/App.class b/chain/target/classes/ru/molokoin/App.class index acfe41ad857916f64bfcf773be318c6899be5c3f..353db4999d8eb3e719826e279f1334dfce8386db 100644 GIT binary patch delta 602 zcmZXQO=}ZT6o#KWNhirT>a?X5Q83Gd21lr$jh|Jk(Wz-H2wjft7+Uio(@8}TLdBi9 zDz0_!#)^)ywG|g`1mOnsC%Et@xDoI8F$uUiyyu+fzUQ3#L;q$NpMGv^1IL(MHzu`q zio=3Izh&2(wdU>SV#A*CT)$>8PR3Bwi4?~bu;i||cFk>6?NTG~s-AB$K~a!eaceEF zd`mEzE9IU4uwrC%%H%X>1POOxK`@f*!`kJWOWu4?%-@K>b0(AMf`L2!Vk1a%L2yVu zmD}A_xhY@ES8_{seb! z+~pt|pLcrarvKhsTywPCfpp+|?sCh&Cm8O7V#e3%hL|NuLjB;^weMP`y~+688;(pD z#u5iR91S^H7)!=#AXa*;Qn5F8 zpo&TMp;IBloT|>VgE}U6*~u!qc*Jg=VDU_`&lw_Qm=BEbkx@RghcE0^FChEpO0MFl YtinU4xrR`l_bD@@CJHLLYH3{m1@m;Bp8x;= delta 106 zcmaFL^^=Y3)W2Q(7#JAL87wz)IWbKRV%C^En>m|{p^t%ufe9!PG+BTp(0(J3#l*k` tB>5Pafg}rqGy@w$AW(!G$P&SJwAIqkaBn0I_n-owLK=ef78knICp zoHr50h)|m%B4^LhU-;|5Oba;^4i zz2i15oJ5|Lx4X0_8`SBw%X5-e>-etIoJo@Mw1qelCeET@;2e$A9`6pcP!yqtrfjq% ztz^N#0nt2Z;XKN`UH+#zTPXGsEwL9Z9EC~$YaOS)`p8)eU5h$POLBi%%pp^JO{RgE z^{(%`Efyf?6=$7K2|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