/** Return the result of destructively selecting and arranging items from L according to the procedure described in the problem. */ static IntList select(IntList L) {

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Please answer

/** Return the result of destructively selecting and arranging items
from L according to the procedure described in the problem. */
static IntList select (IntList L) {
1
IntList result;
if (L == null) return null;
3
4
result = L;
L =
6.
result.tail =
while (
IntList p;
8
for (p = result; p != null; p = p.tail) {
10
if (
{
11
L =
12
if (L != null) {
13
IntList next = L.tail;
14
L.tail =
15
p. tail =
16
L =
17
}
break;
}
}
18
19
20
21
if
{
22
IntList next = L.tail;
23
L.tail =
24
result =
25
L =
}
}
26
27
28
return result;
29 }
Transcribed Image Text:/** Return the result of destructively selecting and arranging items from L according to the procedure described in the problem. */ static IntList select (IntList L) { 1 IntList result; if (L == null) return null; 3 4 result = L; L = 6. result.tail = while ( IntList p; 8 for (p = result; p != null; p = p.tail) { 10 if ( { 11 L = 12 if (L != null) { 13 IntList next = L.tail; 14 L.tail = 15 p. tail = 16 L = 17 } break; } } 18 19 20 21 if { 22 IntList next = L.tail; 23 L.tail = 24 result = 25 L = } } 26 27 28 return result; 29 }
The function select performs a reordering of a linked list. Given an IntList L, the
call select (L) will select values from L according to the following procedure:
result =
while L is not empty:
if the first item of L is already in result:
let p be the place in result where the first item of L occurs
remove the first item of L (and discard)
if L is not empty:
remove the first item of L, and insert it immediately after p
in the result
else:
remove the first item ofL and insert it at the beginning of result
else:
return result
For example, if L is the list
[12, 3, 9, 3, 6, 2, 12]
the resulting list would be built by the following sequence of changes:
[] -> [12] -> [3, 12] - [9, 3, 12] -> [9, 3, 6, 12] -> [2, 9, 3, 6, 12]
The step [9, 3, 12] -> [9, 3, 6, 12] removes two elements from L. The last 12 is
skipped entirely, since it is already in the result list and there is nothing following it in L.
Fill in the definition of select to meet its specification. The method is destructive,
and must not use the new operator.
Continued
Transcribed Image Text:The function select performs a reordering of a linked list. Given an IntList L, the call select (L) will select values from L according to the following procedure: result = while L is not empty: if the first item of L is already in result: let p be the place in result where the first item of L occurs remove the first item of L (and discard) if L is not empty: remove the first item of L, and insert it immediately after p in the result else: remove the first item ofL and insert it at the beginning of result else: return result For example, if L is the list [12, 3, 9, 3, 6, 2, 12] the resulting list would be built by the following sequence of changes: [] -> [12] -> [3, 12] - [9, 3, 12] -> [9, 3, 6, 12] -> [2, 9, 3, 6, 12] The step [9, 3, 12] -> [9, 3, 6, 12] removes two elements from L. The last 12 is skipped entirely, since it is already in the result list and there is nothing following it in L. Fill in the definition of select to meet its specification. The method is destructive, and must not use the new operator. Continued
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY