Delphi algorithm and Data Structure Learning and sentiment [6]: A simple "one-way linked list"

Source: Internet
Author: User
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; procedure formcreate (Sender: tobject); Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} type pmyrec = ^ myrec; {define pmyrec as the pointer type of the myrec structure below} myrec = Record Name: String [8]; age: word; Link: pmyrec; {The structure also contains pointers of the same type, used to link other similar structures} end; var R1, R2, R3, R4: myrec; {make R1, R2, R3, and R4 an interlocking "chain". This is a simple "linked list"} procedure tform1.formcreate (Sender: tobject); begin r4.name: = 'lily'; r4.age: = 16; r4.link: = nil; r3.name: = 'zhangsan'; r3.age: = 61; r3.link: = @ R4; r2.name: = 'Qian 2'; r2.age: = 24; r2.link: = @ R3; r1.name: = 'zhao yi'; r1.age: = 42; r1.link: = @ R2; end; {now, the entire chain can be accessed through R1; but this chain is unidirectional, so it is called "unidirectional linked list"} procedure tform1.button1click (Sender: tobject); begin showmessage (r1.name ); {Zhao Yi} showmessage (r1.link ^. name); {} showmessage (r1.link ^. link ^. name); {Zhang San} showmessage (r1.link ^. link ^. link ^. name); {Li Si} end; {Reading data through the structure pointer can omit ^; so button1click can be abbreviated as:} procedure tform1.button2click (Sender: tobject); begin showmessage (r1.name ); {Zhao Yi} showmessage (r1.link. name); {} showmessage (r1.link. link. name); {Zhang San} showmessage (r1.link. link. link. name); {Li Si} end; end.
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.