Single linked list - delphi -
I am starting to learn programming.
I have to do this (HW) program which I can add in the name and surname of the example, by adding it to a link list, I can display this list of single links.
I tried to do this, it is compiling the program and it is also working. I can add data and it is displayed. But I do not underneath and make a mistake. I am adding the first person, it is displayed, I am adding another person to it, it is also displayed but the data of the first person has been added by another person which I am adding. So I have two identical records. Listbox is only displaying data from a single linked list, so I think there is no problem with it. Each pointer will tell different figures, so why is each record similar to the last one?
Here is my code: type wskaznik = ^ Lista; List = record LP: string; Dane: string; Wsk: wskaznik; End; Var Form 1: Teform 1; First, present: wskaznik; Tekst: string; Liczba: string; I, K: integer; Implementation {$ R * .lfm} {TForm1} Process AddToList (Den: string; lp: string; var current: wskaznik); Var prev, Next: wskaznik; If the current & lt; & Gt; Zero starts with: = ON; Next: = Current ^. Wsk; End and first start: = zero; Next: = zero; End; New (current); Current ^ .dane: = Dane; Current ^ .lp: = lp; Current ^ .wsk: = next; If the previous & lt; & Gt; Zero then pre ^. Wsk: = ON; End; Process GetAddr (Dane: string; var first, present: wskaznik); Var Next: wskaznik; Get started if the first & lt; & Gt; Zero then starts Next: = First; Repeat if next ^ .wsk & lt; & Gt; Zero then next: = Next ^ .wsk (Next ^ .wsk = zero) or (Next ^ .dane = dane); Current: = Next; End; End; Process GetNum (n: integer; var first, present: wskaznik); Var Next: wskaznik; Get started if the first & lt; & Gt; Zero then if n = 1 is present then: = first and if (n = 2) and (first ^. Wsk = zero) then n: = 0 and further start next: = first; I: = 1; Repeat Inc. (i); If the next ^ .wsk & lt; & Gt; Zero then next: = Next ^ .wsk (i = n) or (next ^ .wsk = zero); If (next ^ .wsk = zero) and (i and lt; n) then n: = 0 and current: = next; End; End; process list; Var l: integer; Start form1.listbox1. Clear; Form1.listbox2.Clear; For L: = 1 I start the gatenum (L, first, present); If L & gt; 1 then form1.listbox1.items.add (currently ^ .dane); Form1.listbox2.items.add (currently ^ .lp); End; End; Less to find process (Dane: string; lp: string; on first, current: vascozic); Var tmp, Next: wskaznik; Get started if the first & lt; & Gt; Zero then starts Next: = First; Repeat if (next ^ .wsk & lt; & gt; zero) then start tmp: = next; Next: = Next ^ .wsk; End; Unless (next ^ .wsk = zero) or (Next ^ .dane & gt; Dane); If the next ^ .dane & gt; DEN then present: = TMP other present: = next; If next ^. LP & gt; LP then current: = TMP other current: = next; End; End; Process TForm1.Button1Click (Sender: Tubbed); Initial Inc (i); Investigator (edit 1. text, edit 2. text, first, current); Editual (edit.1 text, edit 2. text, current); Label 3 Caption: = 'Elemento:' + IntotoTr (I-1); //edit1.SetFocus; List; End; End.
You never assign before (< Code> first list is about to begin). The first time you call AddToList, you should assign Current to first
Comments
Post a Comment