-
Path: news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.
atman.pl!goblin3!goblin1!goblin.stu.neva.ru!feed.xsnews.nl!fbe001.ams.xsnews.nl
!peer03.fr7!news.highwinds-media.com!newsfeed.neostrada.pl!unt-exc-01.news.neos
trada.pl!unt-spo-b-01.news.neostrada.pl!news.neostrada.pl.POSTED!not-for-mail
Content-Type: text/plain; charset=iso-8859-2; format=flowed; delsp=yes
Newsgroups: pl.comp.programming
Subject: Re: Jak przeszukiwać drzewo z przerwami ?
References: <nf6stq$qmg$1@node2.news.atman.pl>
Date: Wed, 20 Apr 2016 06:03:02 +0200
MIME-Version: 1.0
Content-Transfer-Encoding: Quoted-Printable
From: "Jordan Szubert" <u...@j...us.to>
Organization: HELL inc.
Message-ID: <o...@a...mshome.net>
User-Agent: Opera Mail/1.0 (Win32)
Lines: 77
NNTP-Posting-Host: 83.22.51.203
X-Trace: 1461124983 unt-rea-a-02.news.neostrada.pl 22841 83.22.51.203:48623
X-Complaints-To: a...@n...neostrada.pl
X-Received-Bytes: 2898
X-Received-Body-CRC: 2800204564
Xref: news-archive.icm.edu.pl pl.comp.programming:209318
[ ukryj nagłówki ]Dnia 20-04-2016 o 05:26:49 Borneq <b...@a...hidden.pl> napisał(a):
> Większość operacji na drzewie robi się rekurencyjnie. Tak jak na
> przykład wypisanie wszystkich znalezionych ciągów.
> Wypisz(root) woła Wypisz(1), Wypisz(2)...
> Ale teraz chcę zrobić coś takiego:
> Control+F ma znaleźć pierwsze wystąpienie ciągu, (np. przeszukiwanie w
> rejestrach lub jakimkolwiek innym drzewie z danymi) i stanąć na
> znalezionym węźle, niezależnie jak zagłębiony.
> Naciskając F3 zaczynamy od tego węzła i dalej szukamy.
> Chyba trzeba zrobić sztuczny stos na liście (wektorze, chodzi mi ogólnie
> C++, a zwłaszcza teraz o C#) zamiast rekurencji.
> Jak to wykonać? W C#
w C# kompilator zrobi za ciebie sporo roboty:
public class Node : IEnumerable<Node> {
public string Name;
public List<Node> Children = new List<Node>();
public IEnumerator<Node> GetEnumerator() {
yield return this;
foreach(var c in Children) {
foreach(var e in c) {
yield return e;
}
}
}
System.Collections.IEnumerator
System.Collections.IEnumerable.GetEnumerator() {
return this.GetEnumerator();
}
}
IEnumerator<Node> lastSearch = null;
Node ControlF(Node root, string needle) {
{
var td = lastSearch as IDisposable;
if(td != null) {
td.Dispose();
}
}
lastSearch = root.Where(n => n.Name == needle).GetEnumerator();
if(lastSearch.MoveNext()) {
//has at least one result
return lastSearch.Current;
} else {
//nothing found
return null;
}
}
Node F3() {
if(lastSearch == null) {
return null;
}
if(!lastSearch.MoveNext()) {
//no more results
return null;
} else {
return lastSearch.Current;
}
}
//nie testowalem, moga byc bledy
--
Jordan Szubert
skype:jordanszubert
Następne wpisy z tego wątku
- 20.04.16 16:08 Borneq
- 20.04.16 16:36 Borneq
- 20.04.16 17:00 Borneq
- 20.04.16 18:37 Jordan Szubert
- 21.04.16 05:41 Borneq
Najnowsze wątki z tej grupy
- Do czego nadaje się QDockWidget z bibl. Qt?
- Bibl. Qt jest sztucznie ograniczona - jest nieprzydatna do celów komercyjnych
- Co sciaga kretynow
- AEiC 2024 - Ada-Europe conference - Deadlines Approaching
- Jakie są dobre zasady programowania programów opartych na wtyczkach?
- sprawdzanie słów kluczowych dot. zła
- Re: W czym sie teraz pisze programy??
- Re: (PDF) Surgical Pathology of Non-neoplastic Gastrointestinal Diseases by Lizhi Zhang
- CfC 28th Ada-Europe Int. Conf. Reliable Software Technologies
- Młodzi programiści i tajna policja
- Ada 2022 Language Reference Manual to be Published by Springer
- Press Release - AEiC 2023, Ada-Europe Reliable Softw. Technol.
- Ada-Europe - AEiC 2023 early registration deadline approaching
- Ada-Europe Int.Conf. Reliable Software Technologies, AEiC 2023
- Ile cykli zajmuje mnożenie liczb 64-bitowych?
Najnowsze wątki
- 2024-05-20 Fiat 125p wer. pikup - w PRL moszna było, w III Reczy [pospolitej] nie moszna
- 2024-05-19 Pożar salonu z chińskimi elektrykami
- 2024-05-18 LED
- 2024-05-19 ceny nieruchomości
- 2024-05-18 Szczecin => UX/UI Designer <=
- 2024-05-18 Warszawa => Mid PHP Developer (Laravel) <=
- 2024-05-18 Warszawa => Software .Net Developer <=
- 2024-05-18 Warszawa => Mid/Senior QA Engineer <=
- 2024-05-18 Ulm => Solution Architect (sichere Kommunikation und IoT-Loesungen <=
- 2024-05-18 Katowice => Head of Virtualization Platform Management and Operating S
- 2024-05-18 Warszawa => SAP WM Consultant / Execution <=
- 2024-05-18 Wrocław => Consultant/Implementer Comarch ERP XL <=
- 2024-05-18 Gdańsk => Head of International Freight Forwarding Department <=
- 2024-05-18 Warszawa => Account Manager (Recruitment Services) <=
- 2024-05-18 Łódź => Salesperson - CRM Systems <=