From: "[taurus AT ptel DOT net]" Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie Question : Polygon class Date: Tue, 01 Jul 1997 10:44:28 -0500 Organization: MEANS Lines: 39 Message-ID: <33B925DC.3C801F3D@ptel.dot.net> References: <33B920A5 DOT 3A70 AT singnet DOT com DOT sg> Reply-To: taurus AT ptel DOT dot DOT net NNTP-Posting-Host: rushford-30.dialup.means.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Tan Mu Yen wrote: > > I am trying to write a polygon class that allows me to add vertex to it > using linked list ... ie I can add or delete a vertex anytime using > the polygon ... > > Anyone has any idea? pls help me! I wouldn't try it if I were you, linked lists can be very useful, but for storing vertexes (which need to be accessed often, and not always in consecutive order) a simple array is much nicer. If you need to add & delete vertexes, just make the array large enough to hold the maximum number of vertexes & keep a record of how many you actually are using: typedef struct { int num_verts; VERTEX verts[MAX_VERTS]; . . . } POLY; To delete a vert 'v' just do: memcpy(ply->verts[v],ply->verts[v+1],ply->num_verts-v-1); where ply = POLY*. (This is slower than a linked list, but not by much, and you're not going to be deleting verts as often as you'll be using them.) Just as a guess... You're trying to make an editor, aren't you? If that's the case and you'll not be modifying the polygons in the program that finally uses them, just write and read num_verts vertexes from the storage file, then you'll not be wasting memory or disk space. Hope this helps, Sincerely, Joshua Heyer imwho AT hotmail DOT com ********************************************************************** Never let your sense of morals prevent you from doing what is right. -- Salvor Hardin, "Foundation" **********************************************************************