Sei sulla pagina 1di 74

CHAPTER 4

LINKED LIST STRUCTURES

Data Structures Featuring Java Sridhar Radhakrishnan

Linked List Structures


Limitation of arrays: An array cannot be expanded and so must be created with enough capacity for the maximum intended use. Limitation of vectors: Though they can be expanded, they produce fragmentation of memory. So, if rapid access to elements by index is not required and sequential access suffices, then LINKED LISTS can be used. Linked list can be thought of as resembling an anchor

chain.

It is a chain of elements.

Data Structures Featuring Java Sridhar Radhakrishnan

Example of an Use of Linked List Structure


Example: An object belonging to the class Student can now be created using the following:
Student oneStudent = new Student ();

Memory space is allocated for the object. The following statement creates a Student reference with a name of twoStudent. Student twoStudent; No new memory space created. The following statement initializes the pointer: twoStudent = oneStudent; Pointer twoStudent points to the same location as oneStudent.

Data Structures Featuring Java Sridhar Radhakrishnan

Example of an Use of Linked List (cont.)


Subclass of the Student class is given below: class linkedStudent extends Student { linkedStudent nextStudent; } The following statements create two objects belonging to the linkedStudent. firstStudent = new linkedStudent (); secondStudent = new linkedStudent (); We can thus dynamically allocate a series of record locations and tie them together with pointer fields. This series of objects, tied together with pointer fields, is called a linked structure.
Data Structures Featuring Java Sridhar Radhakrishnan

Creating Linked List Objects


The following statements create two objects belonging to the class linkedStudent.

firstStudent.nextStudent = secondStudent;
secondStudent.nextStudent = null;

null

firstStudent

secondStudent

Data Structures Featuring Java Sridhar Radhakrishnan

Creation of a Chain of Lists


The following program segment creates a chain of students. firstStudent and linkedStudent temp, current; current point to current the same node int i; firstStudent firstStudent = new linkedStudent (); current = firstStudent; for (i=0; i < 9; i++) { temp = new linkedStudent (); current.nextStudent = temp; current = temp; } current.nextStudent = null;

Data Structures Featuring Java Sridhar Radhakrishnan

Creation of a Chain of Lists (cont.)


When the value of i is 0, a new node pointed by temp is created. First node pointed by current is linked to the new node.The value of the current pointer is moved to the new node shown by dotted line.

firstStudent

current

temp

At the end of the loop, there are a total of 10 nodes created and the current pointer points to the last node in the linkedlist. nextstudent pointer of the last node points to null.
when i=0 i=1 i=8 i=9
null current

firstStudent current

Data Structures Featuring Java Sridhar Radhakrishnan

Traversal and Insert After


public static linkedStudent lookFor (linkedStudent firstStudent, String newName) { linkedStudent current; current = firstStudent; while ((equal (current.Name, newName) == 0)) && (current != null)) {current = current.nextStudent; } return current; } temp = lookFor (firstStudent, Smith); if (temp != null) { newStudent.nextStudent = temp.nextStudent; temp.nextStudent = newStudent; }
Data Structures Featuring Java Sridhar Radhakrishnan

Deletion from a Linked List


public static linkedStudent deleteStudent (linkedStudent firstStudent, String deleteName) { linkedStudent previous, current; if (firstStudent.Name.equal(deleteName)) { firstStudent = firstStudent.nextStudent; } else { previous = firstStudent; current = previous.nextStudent; Java code for Deletion cont.

Data Structures Featuring Java Sridhar Radhakrishnan

Deletion from a Linked List (cont.)


while ( (current != null) && (current.Name.equal(deleteName))) { previous = current; current = current.nextStudent; } if (current != null) { previous.nextStudent = current.nextStudent; }

} return firstStudent;
}
Data Structures Featuring Java Sridhar Radhakrishnan

10

Deletion Shown Pictorially


Smith

null

firstStudent

After deletion, the firstStudent pointer will point to the node given by the dotted arrow if Smith is contained in the first node.

Smith

null

firstStudent previous current

previous

current

Otherwise, after deletion,the nextStudent pointer corresponding to the previous node will point to the node pointed by current. nextstudent and is shown by a dotted arrow.
Data Structures Featuring Java Sridhar Radhakrishnan

11

Deletion using Single Pointer


Let current point to the node that is to be deleted. Replace the contents of node current with with the contents of the the node current. nextStudent. Now, two nodes have exactly the same contents.But during traversal, the old current. nextstudent will be skipped entirely. Example: Node containing John is the one that follows the node pointed by current.The replace operation replaces Smith with John and the new pointer assignment is null shown by dotted arrow.
Smith John
John

null

firstStudent
Data Structures Featuring Java Sridhar Radhakrishnan

current
12

Abstract Data Type for a Linked List


create() // creates an empty linked list isEmpty() // returns true if the list is empty, but otherwise returns false size() // returns the number of nodes in the list add (object) // adds object to the beginning of the list info () // returns the data from the head node, or null if the list is empty next () // returns the linked list pointed by this linked list setNext () // attaches a linked list following the head node. The linked list \ // previously following that head node is returned. delete () // deletes the first node of the linked list
Data Structures Featuring Java Sridhar Radhakrishnan

13

Exception Classes
import java.io.*; public class LinkedListException extends Exception { } public class LinkedListAddedNull extends LinkedListException { }

A linked list is recursively defined: A linked list points to

another linked list.

Data Structures Featuring Java Sridhar Radhakrishnan

14

Operations Executable on a Linked List


Several primitive operations that can be executed on a linked data structure are:

Traverse a linked list.


Search for an object in the linked list.

Insert an object into the linked list.


Delete an object from a linked list.

Get an object at a particular position in the linked list.

Data Structures Featuring Java Sridhar Radhakrishnan

15

LinkedListADT Class Header File


import java.io.*; import java.util.*; public interface LinkedListADT { public Object info (); // returns the object in the head of the linked list, // or null if the list is empty public LinkedListADT next (); // returns the linkedList pointed by this linkedList public boolean isEmpty(); // returns true if the list is empty, // but otherwise returns false public void add (Object object) throws LinkedListAddedNull; // adds object to the beginning of the list LinkedListADT Class Header File cont..
Data Structures Featuring Java Sridhar Radhakrishnan

16

LinkedListADT Class Header File (cont.)


public LinkedListADT setNext (LinkedListADT next) throws LinkedListAddedNull; // attaches next as _next field of list; // returns old _next field. // if next is empty and current list is also empty, // no effect and null is returned. // if current list is empty but next is not, throws exception. public void insertAt (Object newObj, int position)throws LinkedListAddedNull; // inserts newObj so that it will be at node number position // (counting the head node as 0) public Object infoAt (int position); // return the object in the linked list at the location // specified by position, or null if position is beyond // the end of the linked list LinkedListADT Class Header File cont..
Data Structures Featuring Java Sridhar Radhakrishnan

17

LinkedListADT Class Header File (cont.)


public Object find (Object key); // returns a node matching key or null if none matches public Object delete (); // deletes the first node of the linked list, if any, and // returns it. Returns null if the list was empty. public Object delete (Object key); // deletes the node matching key, if any, // and returns it; otherwise returns null public Object deleteAt (int position); // delete an object in the linked list at the location specified // by position and return the object that is deleted, or null // if position is beyond the end of the linked list public int size(); // returns the number of nodes in the list public Enumeration enumerator (); // returns an enumeration of the data contained in the list
Data Structures Featuring Java Sridhar Radhakrishnan

18

Linked List Enumeration Class Methods


import java.util.Enumeration; class LLEnumerator implements Enumeration { protected LinkedList _LL; // _LL moves from original head through // list until it reaches an empty list public LLEnumerator (LinkedList LL) // LL = head of list to enumerate { _LL = LL; } public boolean hasMoreElements () { return ((_LL != null) && (!_LL.isEmpty())); } LinkedListEnumerator Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

19

Linked List Enumeration Class Methods (cont.)


public Object nextElement () { Object oTemp = null; if ((_LL == null) || (_LL.isEmpty())) { return null; } oTemp = _LL.info (); _LL = (LinkedList) _LL.next(); return oTemp; } }

Data Structures Featuring Java Sridhar Radhakrishnan

20

LinkedList Class Methods


import java.util.Enumeration; public class LinkedList implements LinkedListADT { protected Object _info; protected LinkedList _next; public LinkedList () { _info = null; _next = null; } public LinkedList (Object info) { _info = info; _next = null; } LinkedList Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

21

LinkedList Class Methods (cont.)


protected LinkedList (Object info, LinkedList next) throws LinkedListAddedNull // create a linked list as head of an existing list { if (info == null) { throw new LinkedListAddedNull (); } _info = info; _next = next; } LinkedList Class Methods cont..

Data Structures Featuring Java Sridhar Radhakrishnan

22

LinkedList Class Methods (cont.)


public void add (Object object) throws LinkedListAddedNull { if (object == null) {throw new LinkedListAddedNull (); } if (_info == null) { _info = object; } else { LinkedList newList = new LinkedList (_info, _next); _info = object; _next = newList; } } LinkedList Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

23

LinkedList Class Methods (cont.)


public void insertAt (Object newObj, int position) throws LinkedListAddedNull { if (newObj == null) throw new LinkedListAddedNull(); if (position == 0) { add (newObj); } else { if (_next == null) { _next = new LinkedList(newObj); } else { _next.insertAt (newObj, position - 1); } } } LinkedList Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

24

LinkedList Class Methods (cont.)


public Object info () { return _info; } public Object infoAt (int position) { if (position == 0) { return _info; } if (_next == null) { return null; } return _next.infoAt (position - 1); } public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } LinkedList Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

25

LinkedList Class Methods (cont.)


public Object delete () { Object temp = _info; if (_next == null) { _info = null; } else { LinkedList oldnext = _next; _info = _next._info; _next = _next._next; // the purpose of these two lines is to remove any // stray pointers into the linked list oldnext._info = null; oldnext._next = null; } return temp; } LinkedList Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

26

LinkedList Class Methods (cont.)


public Object delete (Object key) { Object temp = _info; if (key == null) return null; if (key.equals (_info)) { return delete(); } if (_next == null) { return null; } return _next.delete (key); } public Object deleteAt (int position) { if (position == 0) { return delete(); } if (_next == null) { return null; } return _next.deleteAt (position - 1); } LinkedList Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

27

LinkedList Class Methods (cont.)


public boolean isEmpty () { return (_info == null); } public LinkedListADT setNext (LinkedListADT next) throws LinkedListAddedNull { if (isEmpty()) { if (next != null) throw new LinkedListAddedNull (); return null; } LinkedListADT temp = _next; _next = (LinkedList) next; return temp; } LinkedList Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

28

LinkedList Class Methods (cont.)


public boolean isEmpty () public LinkedListADT next () { return (_next); } public int size () { if (_next == null) { if (_info == null) return 0; else return 1; } else return 1 + _next.size(); } LinkedList Class Methods cont..
Data Structures Featuring Java Sridhar Radhakrishnan

29

LinkedList Class Methods (cont.)


public Enumeration enumerator () { return new LLEnumerator (this); } public String toString() { Enumeration e = enumerator(); String s = ""; while (e.hasMoreElements()) { s = s + " " + e.nextElement(); } return s; }
Data Structures Featuring Java Sridhar Radhakrishnan

30

Add Method Implementation(Adding an Object into empty list)


public void add (Object object) throws LinkedListAddedNull { if (object == null) {throw new LinkedListAddedNull (); } if (_info == null) { _info = object; } else { LinkedList newList = new LinkedList (_info,_next); _info = object; _next = newList; } }

Consider a case where we have an empty list and we want to add an object B to it.
Inserting B

_info=NULL and hence new object is inserted into the list.


Data Structures Featuring Java Sridhar Radhakrishnan

31

Add Method Implementation (Adding an Object into empty list) (cont.)


public void add (Object object) throws LinkedListAddedNull { if (object == null) {throw new LinkedListAddedNull (); } if (_info == null) { _info = object; } else { LinkedList newList = new LinkedList (_info,_next); _info = object; _next = newList; } }

B
_info is not equal to NULL.

Data Structures Featuring Java Sridhar Radhakrishnan

32

Add Method Implementation (Adding an Object into empty list) (cont.)


public void add (Object object) throws LinkedListAddedNull { if (object == null) {throw new LinkedListAddedNull (); } if (_info == null) { _info = object; } else { LinkedList newList = new LinkedList (_info,_next); _info = object; _next = newList; } }

Consider another case where we have two linked lists B and C. We want to add an object A to it.

B
object = C. So, object is not empty and no exceptions occur.
Data Structures Featuring Java Sridhar Radhakrishnan

33

Add Method Implementation (Adding an Object into empty list) (cont.)


public void add (Object object) throws LinkedListAddedNull { if (object == null) {throw new LinkedListAddedNull (); } This is not executed. if (_info == null) { _info = object; } else { LinkedList newList = new LinkedList (_info,_next); _info = object; _next = newList; } }

Consider another case where we have two linked lists B and C. We want to add an object A to it.

_info is not equal to NULL.


Data Structures Featuring Java Sridhar Radhakrishnan

34

Add Method Implementation (cont.)


public void add (Object object) throws LinkedListAddedNull { if (object == null) {throw new LinkedListAddedNull (); } if (_info == null) { _info = object; } else { LinkedList newList = new LinkedList (_info,_next); _info = object; _next = newList; } }
original list

B B
newlist

Data Structures Featuring Java Sridhar Radhakrishnan

35

Add Method Implementation (cont.)


public void add (Object object) throws LinkedListAddedNull { if (object == null) {throw new LinkedListAddedNull (); } if (_info == null) { _info = object; } else { LinkedList newList = new LinkedList (_info,_next); _info = object; _next = newList; } The object A is to be added. So, the _info field of the }

original node is made as A. original list

A B B
newlist

Data Structures Featuring Java Sridhar Radhakrishnan

36

Add Method Implementation (cont.)


public void add (Object object) throws LinkedListAddedNull { if (object == null) {throw new LinkedListAddedNull (); } if (_info == null) { _info = object; } else { LinkedList newList = new LinkedList (_info,_next); _info = object; _next = newList; } The original list is now made to point to the newlist. }
original list Originals next list

A B
newlist

Data Structures Featuring Java Sridhar Radhakrishnan

37

Methods for Inserting(Adding) Data


Inserting A on an empty list

A B B
Original list and new node

Empty list

C
Non-Empty list

Inserting A

New node linked in

B B

Original list

New node

Originals next list

A
Data Structures Featuring Java Sridhar Radhakrishnan

C
38

Find Method Implementation


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } Consider a case where we have 4 linked lists A,B,C,D. Say, we have to find the list C. key = C , *_info = A A B C D
null

Key is not equal to NULL and so does not return NULL.

Data Structures Featuring Java Sridhar Radhakrishnan

39

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key = C *_info = A A *_info key is not equal to *_info.
Data Structures Featuring Java Sridhar Radhakrishnan

null

40

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key = C *_info = A A *_info _next is not NULL and so does not return NULL.
Data Structures Featuring Java Sridhar Radhakrishnan

null

41

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key A *_info find method for the next object pointed by _next is executed.
Data Structures Featuring Java Sridhar Radhakrishnan

= C B C D
null

42

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key = C *_info = B A *_info Key is not equal to NULL and so does not return NULL.
Data Structures Featuring Java Sridhar Radhakrishnan

null

43

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key = C *_info = B A *_info key is not equal to *_info.
Data Structures Featuring Java Sridhar Radhakrishnan

null

44

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key = C *_info = B A *_info _next is not NULL and so does not return NULL.
Data Structures Featuring Java Sridhar Radhakrishnan

null

45

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key A *_info = C B *_info C D
null

find method for the next object pointed by _next is executed.


Data Structures Featuring Java Sridhar Radhakrishnan

46

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key = C *_info = C A B *_info Key is not equal to NULL and so does not return NULL.
Data Structures Featuring Java Sridhar Radhakrishnan

null

47

Find Method Implementation (cont.)


public Object find (Object key) { if (key == null) return null; if (key.equals (_info)) { return _info; } if (_next == null) { return null; } return _next.find (key); } key = C *_info = C A B *_info key is equal to *_info. So, the value C ,i.e, *_info is returned back.
Data Structures Featuring Java Sridhar Radhakrishnan

DATA FOUND!!!
C D
null

48

Main Method for Linked List Class


public static void main (String args[]) { String [] movies = {2001, Tron, Wargames, Robocop, Robot Monster, Colossus, A set of characters Forbidden Planet}; which are to be inserted. LinkedList L = new LinkedList (); try { for (int i = 0; i < movies.length; i++) { L.insertAt (movies[i], i); Exception occurs if we try to insert more than what has been provided. } Inserts a number of characters } into the linked list. catch (LinkedListAddedNull e) {System.out.println ("This couldn't happen");} Main Method cont.

Data Structures Featuring Java Sridhar Radhakrishnan

49

Main Method for Linked List Class (cont.)


System.out.println (); Linkedlist.java System.out.println (L); Removes the string L.deleteAt (4); System.out.println (L); at position 4. for (int i = 0; i < 10; i++) { L.delete (); Exception occurs if we try } to remove from an empty list. System.out.println (">" + L + "<"); } } This main() function inserts a number of elements and prints the list (to show the order); then it deletes one number and prints the list again to show that the correct element was deleted; then it attempts to delete more elements than actually exist in the list, demonstrating that no error occurs.
Data Structures Featuring Java Sridhar Radhakrishnan

50

Doubly Linked Lists


Doubly linked list is a modified type of linked list. In a linked list, by adding another pointer _previous,which points to the previous element of the linked list, we can get a doubly linked list.

null

The doubly linked list can be traversed backwards and forwards from any node of the linked list using _previous and _next pointers, respectively.

Data Structures Featuring Java Sridhar Radhakrishnan

51

Circularly Linked Lists


We make the last node of the linked list point to the first node of the linked list to get a circularly linked list.

They are useful whenever we need to process elements in a round robin fashion.For example, each node in a circularly linked list could correspond to a process(a program in execution) that is waiting for CPU time. Another variation of circularly linked list is the circularly linked doubly linked linked list. Here the _previous pointer of the first element points to the last element of the doubly linked list and the _next pointer of the last element points to the first element.
Data Structures Featuring Java Sridhar Radhakrishnan

52

Generalized lists
In the definition of linked lists, another field of data type called _sublist is added as a result of which we can see that each node of the linked list points to 2 linked lists: one using the _next pointer and other using the _sublist pointer
a b
null

c f
null null

null

( a ( de ( i )) b c ( fgh )
h
null null null

d
null

i
null

null

Parenthesis form of this generalized list: ( a ( de ( i )) b c ( fgh ) First level elements : a, b, c Second level elements: de,fgh and Third level elements : i
Data Structures Featuring Java Sridhar Radhakrishnan

53

Other Implementation of Linked Lists


Vectors can be used to implement Linked Lists as objects can be inserted and deleted from any position within the vector.

Vectors can also be implemented using arrays as follows:Consider the following linked list:
a b c d
null

The above linked list can be represented in an array of objects as shown below:
0 1 2 3 4 5 6 _info null a c b null d null _next -1 3 5 2 -1 -1 -1

Data Structures Featuring Java Sridhar Radhakrishnan

54

Main Memory Management


Main memory is divided into two partitions: One to accommodate the operating system and the other to the user processes. Assumptions: Each user process(job) requests a particular size of memory that must be available contiguously(one block). If there is a contiguous block of memory that is large enough to fit the new job,then the new job is loaded into memory. When a job terminates, its allocated block of memory becomes free space or hole.
55

Data Structures Featuring Java Sridhar Radhakrishnan

Memory Management Using Best Fit Algorithm


Consider the following memory scheme in which the users space is free. Initially, 0 Operating
system

400K

2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

56

Memory Management Using Best Fit Algorithm (cont.)


Allocate P1 600K 0 400K
P1
Operating system

1000K

2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

57

Memory Management Using Best Fit Algorithm (cont.)


Allocate P2 1000K 0 400K
P1
Operating system

1000K
P2

2000K

2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

58

Memory Management Using Best Fit Algorithm (cont.)


Allocate P3 300K 0 400K
P1
Operating system

1000K
P2

2000K
2300K 2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

P3

59

Memory Management Using Best Fit Algorithm (cont.)


Terminate P2 0 400K
P1
Operating system

1000K
P2

2000K
P3

2300K 2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

60

Memory Management Using Best Fit Algorithm (cont.)


Allocate P4 700K 0 400K
P1
Operating system

1000K
P4

1700K

2000K
P3

2300K 2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

61

Memory Management Using Best Fit Algorithm (cont.)


Allocate P4 700K 0 400K
P1
Operating system

1000K
P4

1700K

2000K
P3

2300K 2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

62

Memory Management Using Best Fit Algorithm (cont.)


Terminate P1 0 400K
P1
Operating system

1000K
1700K

P4

2000K
P3

2300K 2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

63

Memory Management Using Best Fit Algorithm (cont.)


Allocate P5 400K 0 400K
Operating system

900K 1000K
1700K

P4

2000K
P3

2300K 2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

64

Memory Management Using Best Fit Algorithm (cont.)


Allocate P5 500K 0 400K
Operating system

P5

900K 1000K
1700K

P4

2000K
P3

2300K 2560 k
Data Structures Featuring Java Sridhar Radhakrishnan

65

Java Implementation Strategy for Memory Management


Singly linked list representation of the space in memory will allow us to implement the above operations.

Partition class needs to be created for this purpose. public class Partition { int beginAddress; // beginning address of the partition int endAddress; // end address of the partition boolean hole; // hole is false if it is occupied by a // process, // true otherwise. int processID; // if hole is false, it contains the process // identifier of the process using the // partition, // otherwise -1 };
Data Structures Featuring Java Sridhar Radhakrishnan

66

Memory Management Shown Pictorially


Each node of the linked list stores a partition object.Initially, there exists a single node with the object whose fields are initialized as
400

beginAddress=400; endAddress=2560; hole=true; processID=-1;

2560

true
-1

null

Data Structures Featuring Java Sridhar Radhakrishnan

67

Memory Management Shown Pictorially (cont.)


To allocate P1 600K, we need to find a node with hole set to true and (endAddress-beginAddress)>=600
400
999

1000
2560

false
1

true
-1

null

Data Structures Featuring Java Sridhar Radhakrishnan

68

Memory Management Shown Pictorially (cont.)


Allocate P2 1000K:

400
999

1000
1999

2000
2560

false
1

false
2

true
-1

null

Data Structures Featuring Java Sridhar Radhakrishnan

69

Memory Management Shown Pictorially (cont.)


Allocate P3 300K:

400
999

1000
1999

2000
2299

2300
2560

false
1

false
2

false
3

true
-1

null

Data Structures Featuring Java Sridhar Radhakrishnan

70

Memory Management Shown Pictorially (cont.)


Terminate P2:

400
999

1000
1999

2000
2299

2300
2560

false
1

true
-1

false
3

true
-1

null

Data Structures Featuring Java Sridhar Radhakrishnan

71

Memory Management Shown Pictorially (cont.)


Allocate P4 700K:

400
899

1000
1699

1700
1999

2000
2299

2300
2560

false
1

false
4

true
-1

false
3

true
-1

null

Data Structures Featuring Java Sridhar Radhakrishnan

72

Memory Management Shown Pictorially (cont.)


Terminate P1:

400
999

1000
1699

1700
1999

2000
2299

2300
2560

true
-1

false
4

true
-1

false
3

true
-1

null

Data Structures Featuring Java Sridhar Radhakrishnan

73

Memory Management Shown Pictorially (cont.)


Allocate P5 500K:

400
899

900
999

1000
1699

1700
1999

2000
2299

2300
2560

false
5

true
-1

false
4

true
-1

false
3

true
-1

null

Data Structures Featuring Java Sridhar Radhakrishnan

74

Potrebbero piacerti anche