Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Printing linked lists

Posted on 1998-03-14
5
Medium Priority
?
200 Views
Last Modified: 2010-04-16
Is pushing/popping the only way to print out a linked list (using pointers) to the screen? Also, what is the most efficient way to create multiple linked lists in the same program? Sample algorithms would be helpful...
0
Comment
Question by:chadd082197
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:chadd082197
ID: 1217394
Edited text of question
0
 
LVL 1

Accepted Solution

by:
Nexial earned 200 total points
ID: 1217395
No, you do not need a stack
Dashes used to suppress EE elimination of leading spaces.

TYPE pointertype = ^NODETYPE;
NODETYPE = RECORD
-------------INFO : INFOTYPE;
-------------NEXT : POINTERTYPE
-----------END;


Procedure printlist (list:pointertype)
(* print out value of INFO field of each node of LL *)

var P : pointertype;

begin   (* print the list *)
--P := list;
--WHILE P <> NIL do
----begin (* print data & advance pointer *)
--------writeln(P^.INFO);
--------P := P^.NEXT
----end  (*while *)
end; (*printlist *)



   
0
 

Author Comment

by:chadd082197
ID: 1217396
Looks good...thanks. Any thoughts on the second question? I'm writing a program in which the user can create any number of single linked lists and then manipulate them in various ways (appending nodes, deleting nodes, printing, etc). What I don't know is how to reference the different lists (for example, if the user creates a second list (or ten lists, whatever) how do you keep them separate since you can't "name" a list?).
0
 
LVL 1

Expert Comment

by:Nexial
ID: 1217397
Several thoughts on the second question:

Easiest, but not extremely efficient is to create a single linked list containing the bases of the other linked lists, along with whatever you choose to use as the list identifier.   Then you can
insert/delete list bases at any time.   Use common procedures for
the list manipulations where you pass the procedure a pointer to the node (or the previous node) of the node being manipulated.

Better is for this list to be doubly linked, so that deletion is easier.

Even better (especially if there are a lot of lists) is for this list to be a btree so that insertion, deletion, and searching it are much faster.

See Knuth, Sorting and Searching (Vol III, Art of Computer Programming, for generic list manipulation theory and algorithms.

Source code like I provided before can be found on the net or in many textbooks in the library.
0
 
LVL 2

Expert Comment

by:omsec
ID: 1217398
...to save memory use NEW and DISPOSE
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question