Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   FInd duplicate array and a quick way to search item per line on file?? (https://www.delphipraxis.net/156082-find-duplicate-array-quick-way-search-item-per-line-file.html)

user 19. Nov 2010 10:20

FInd duplicate array and a quick way to search item per line on file??
 
For example I have an sorted array.
array[0]=1
array[1]=3
array[2]=2
array[3]=2
array[4]=4

First,
I use binary search to find an item. I found array[2]. I want to find duplicate item from the array, so I check the next index, if the value of next index doesn't match with array[2], it mean no duplicate item found. Am in right way to find duplicate item?

Second,
I got the duplicate items : array[2] and array[3]. I store them in new array or maybe in stringlist.
I have file contain :
aa
bb
cc
dd
ee

Now, I want to get the value of third line from the file (third line = array[2]). I want to get the value of forth line from the file (forth line = array[3]). The point is I want to retrieve the value from line based on index of duplicate array.

How to do this properly? I don't want to load all lines to stringlist to get the index, because if I have >5000 lines, the memory consumption will large.

Thanks.

s.h.a.r.k 19. Nov 2010 10:39

AW: FInd duplicate array and a quick way to search item per line on file??
 
Your first example is not sorted! But if it would be sorted then you're right.

-- EDIT
You can use Hier im Forum suchenAssignFile(), Hier im Forum suchenReset(), Hier im Forum suchenSeek() and Hier im Forum suchenReadln to get a special line of a file.

user 19. Nov 2010 11:10

AW: FInd duplicate array and a quick way to search item per line on file??
 
Zitat:

Zitat von s.h.a.r.k (Beitrag 1062525)
Your first example is not sorted! But if it would be sorted then you're right.

-- EDIT
You can use Hier im Forum suchenAssignFile(), Hier im Forum suchenReset(), Hier im Forum suchenSeek() and Hier im Forum suchenReadln to get a special line of a file.

Ups sorry! :D

Okey, I'll try. I have to check again that "AssignFile" doesn't load the file into memory. Thanks.

SirThornberry 19. Nov 2010 12:06

AW: FInd duplicate array and a quick way to search item per line on file??
 
if each line of your file has the same length you can calculate at which position the data is.
To access the file a prefer TFileStream

p80286 19. Nov 2010 14:35

AW: FInd duplicate array and a quick way to search item per line on file??
 
Zitat:

Zitat von user (Beitrag 1062520)
For example I have an sorted array.
array[0]=1
array[1]=3
array[2]=2
array[3]=2
array[4]=4

First,
I use binary search to find an item. I found array[2]. I want to find duplicate item from the array, so I check the next index, if the value of next index doesn't match with array[2], it mean no duplicate item found. Am in right way to find duplicate item?

No that is not shure. if You are looking for "2" you might find array[2] or array[3]!
so you have to check the previous and the next index(s).

Greetings
K-H


Alle Zeitangaben in WEZ +1. Es ist jetzt 14:45 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz