Solved

Posted on 1998-03-14
160 Views
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
• 2
• 2

Author Comment

ID: 1217394
Edited text of question
0

LVL 1

Accepted Solution

Nexial earned 50 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

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

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

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

## Featured Post

### Suggested Solutions

In  today’s increasingly digital world, managed service providers (MSPs) fight for their customers’ attention, looking for ways to make them stay and purchase more services. One way to encourage that behavior is to develop a dependable brand of prod…
What is Backup? Backup software creates one or more copies of the data on your digital devices in case your original data is lost or damaged. Different backup solutions protect different kinds of data and different combinations of devices. For e…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

#### Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!