AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Algorithmen, Datenstrukturen und Klassendesign FInd duplicate array and a quick way to search item per line on file??
Thema durchsuchen
Ansicht
Themen-Optionen

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

Ein Thema von user · begonnen am 19. Nov 2010 · letzter Beitrag vom 19. Nov 2010
Antwort Antwort
user

Registriert seit: 13. Jul 2010
25 Beiträge
 
Delphi 2 Desktop
 
#1

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

  Alt 19. Nov 2010, 10:20
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.
  Mit Zitat antworten Zitat
Benutzerbild von s.h.a.r.k
s.h.a.r.k

Registriert seit: 26. Mai 2004
3.159 Beiträge
 
#2

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

  Alt 19. Nov 2010, 10:39
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.
»Remember, the future maintainer is the person you should be writing code for, not the compiler.« (Nick Hodges)

Geändert von s.h.a.r.k (19. Nov 2010 um 10:43 Uhr)
  Mit Zitat antworten Zitat
user

Registriert seit: 13. Jul 2010
25 Beiträge
 
Delphi 2 Desktop
 
#3

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

  Alt 19. Nov 2010, 11:10
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!

Okey, I'll try. I have to check again that "AssignFile" doesn't load the file into memory. Thanks.
  Mit Zitat antworten Zitat
Benutzerbild von SirThornberry
SirThornberry
(Moderator)

Registriert seit: 23. Sep 2003
Ort: Bockwen
12.235 Beiträge
 
Delphi 2006 Professional
 
#4

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

  Alt 19. Nov 2010, 12:06
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
Jens
Mit Source ist es wie mit Kunst - Hauptsache der Künstler versteht's
  Mit Zitat antworten Zitat
Benutzerbild von p80286
p80286

Registriert seit: 28. Apr 2008
Ort: Stolberg (Rhl)
6.659 Beiträge
 
FreePascal / Lazarus
 
#5

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

  Alt 19. Nov 2010, 14:35
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
Programme gehorchen nicht Deinen Absichten sondern Deinen Anweisungen
R.E.D retired error detector
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:22 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