| | |
linked list question
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jul 2005
Posts: 244
Reputation:
Solved Threads: 5
I'm fairly confident with making/destroying linked lists (one of my few strengths compared to other inexperienced coders), but I see what you mean.
For the first node you'd certainly use a method of creating the head node pointer then linking it to the first node, but after that, you can use a temporary pointer to point to the new nodes and link if you're wanting to perform an insertion rather than an append. For supporting inserts, that's actually a bit clearer. Otherwise, you would create pointers to nodes before and after the insert point to keep track of the rest of the list while you added nodes, which is trivially more expensive in terms of memory.
For the first node you'd certainly use a method of creating the head node pointer then linking it to the first node, but after that, you can use a temporary pointer to point to the new nodes and link if you're wanting to perform an insertion rather than an append. For supporting inserts, that's actually a bit clearer. Otherwise, you would create pointers to nodes before and after the insert point to keep track of the rest of the list while you added nodes, which is trivially more expensive in terms of memory.
Explainer of control logic and some basics.
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
"If you seek to drink from a fountain of knowledge, make sure your cup is big enough."
![]() |
Similar Threads
- Minimal element in a linked list? (Computer Science)
- connect linked list (C)
- Circular linked list (C)
- Linked List & Objects (C++)
- "doubly linked list" question (C)
Other Threads in the C Forum
- Previous Thread: random matrix generation
- Next Thread: Hint on where to start
Views: 2634 | Replies: 10
| Thread Tools | Search this Thread |
Tag cloud for C
#include * .net append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue mysql number oddnumber odf opensource overwrite owf pdf performance pointer pointers posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi





