Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

0 ) Write a simple loop that, for each record r in the list L , changes r . dat to be r . dat

0) Write a simple loop that, for each record r in the list L, changes r.dat to be r.dat plus all of the .dat
values in the records that precede r in the (original) list L.
So if the numbers in the list are 3,4,5,6,7, then they are changed to 3,7,12,18,25.
Solution:
sum 0; { So sum is a local identifier }
` L; { where L was defined earlier. The assignment to ` keeps L pointing at the front of the list }
while `6= Nil do { You might prefer null }
sum sum +`.dat
`.dat sum;
``.next
endwhile;
1.1) Write a simple sequence of instructions that processes two singly linked lists Y and M by removing the
first record in Y (if Y 6= Nil) and prepending that record at the front of list M so that M now has this
new element as the first record followed by the old M, and Y no longer contains what had been its first
record. In other words, you have a list Y , and I have a list M. Present instructions that pull off your head,
and place it on top of mine.
1.2) Write a simple loop that reverses the list Y , and gives this new list the name Y .
Does part i make this easier?
1.3) Give a simple, high-level three line description (do this, do that, do this) of an iterative method to modify
L so that for each record r in the list, r.dat is changed to be r.dat plus all of the .dat values in the
records that follow (succeed) r in the (original) list L.
So if the numbers in the list are 3,4,5,6,7, then they are changed to 25,22,18,13,7.
Detailed pseudocode is unnecessary for this part. Does part ii make this easier? (Your answer could be
no.)
1.4) Find a simple, two-pass iterative solution (i.e., which processes all of L twice) to modify L to have the
sums as requested in 1.3, but without ever changing any of its pointers. You can present the pseudocode,
or explain your answer at a higher level.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Third International Conference Achids 2011 Daegu Korea April 2011 Proceedings Part 2 Lnai 6592

Authors: Ngoc Thanh Nguyen ,Chong-Gun Kim ,Adam Janiak

2011th Edition

3642200419, 978-3642200410

More Books

Students also viewed these Databases questions