/FILE: node1.h (part of the namespace main_savitch 5) // PROVIDES: A class for a
ID: 3859428 • Letter: #
Question
/FILE: node1.h (part of the namespace main_savitch 5) // PROVIDES: A class for a node in a linked list and a collection of functions for // manipulating linked list.s /I TYPEDEF for the node class /I Each node of the list contains a piece of data and a pointer to the next node. The // type of the data is defined as node::value type in a typedef statement. The value type /I may be any of the C++ built-in types (int, char, etc.), or a class with a default constructor, // a copy constructor, an assignment operator, and a test for equality I CONSTRUCTOR for the node clas.s // node (const value_type& init data, node* init link) // Postcondition: The node contains the specified data and link / NOTE: The init data parameter has a default value that is obtained from the default /I constructor of the value type. In the ANSI/ISO Standard, this notation is also allowed //for the built-in types, providing a default value of zero. The init_link has a default value of NULL (continued) // NOTE // Some of the functions have a return value that is a pointer to a node. Each of these // functions comes in two versions: a non-const version (where the return value is node) / and a const version (where the return value is const node) EXAMPLES const node *c; // C->ink() activates the const version of link / ist search(c, calls the const version of list search /node *p // p->link activates the non-const version of link // list search(p, calls the non-const version of list search /MEMBER FUNCTIONS for the node class // void set_data(const value_type& new_data) / Postcondition: The node now contains the specified new data / void set link (node* new_link) // Postcondition: The node now contains the specified new link // value_type data() const /Postcondition: The return value is the data from this node.Explanation / Answer
public class Node{
int beginAddress;
int endAddress;
boolean holeFree;
int processId;
Node next;
public Node(int begin,int end){
beginAddress=begin;
endAddress=end;
holeFree=true;
processId=-1;
next=null;
}
public Node(){}
public Node(int begin,int end,int i){
beginAddress=begin;
endAddress=end;
holeFree=false;
processId=i;
}
}
public class Partition{
private Node head;
public Node current;
public int begin;
public int end;
public Node newPartition;
public Partition(int beginAddress,int endAddress,int a){
head=new Node(beginAddress,endAddress);
begin=beginAddress;
end=endAddress;
current=head;
}
public Partition(int beginAddress,int endAddress){
current=new Node(beginAddress,endAddress);
}
public void addProcess(int size,int id){
if((current.endAddress-current.beginAddress>=size)&& current.holeFree==true){
newPartition=new Node(current.beginAddress,current.beginAddress+size-1,id);
newPartition.next=refresh();
System.out.println("beginAddress"+newPartition.beginAddress);
System.out.println("endAddress"+newPartition.endAddress);
}
}
public void print(){
System.out.println("beginAddress"+newPartition.beginAddress);
System.out.println("endAddress"+newPartition.endAddress);
}
public Node refresh(){
current=new Node(newPartition.endAddress+1,end);
return current;
}
public void deleteProcess(int process){
Node temp=head;
while(temp.next!=null){
System.out.println(temp.processId);
temp=temp.next;
}
}
public static void main (String args[]){
Partition p=new Partition(300,3000,1);
p.addProcess(500,1);
p.addProcess(800,2);
p.addProcess(400,3);
p.deleteProcess(5);
System.out.println(p.head.beginAddress);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.