title: memory management using linked list
body: <p>This is  a homework question in relation to memory management implementation using linked lists.<br>
  Each memory process requests of a particular size of memory that must be contiguously large enough to fit the memory and then allocate the process.When a job terminates,its allowed memory becomes free.<br>
  This is the java code I wrote for this.  </p>
  
  <pre><code>public class PartitionNode{
      int beginAddress;
      int endAddress;
      boolean holeFree;
      int processId;
      PartitionNode next;
  
      public PartitionNode(int begin,int end){
           beginAddress=begin;
           endAddress=end;
           holeFree=true;
           processId=-1;
           next=null;
  
  
      }
      public PartitionNode(){}
      public PartitionNode(int begin,int end,int i){
          beginAddress=begin;
          endAddress=end;
          holeFree=false;
          processId=i;
  
      }
  
  }
  
  public class Partition{
      private  PartitionNode head;
      public PartitionNode current;
  
  public  int begin;
  public int end;
  public PartitionNode newPartition;
  public Partition(int beginAddress,int endAddress,int a){
      head=new PartitionNode(beginAddress,endAddress);
      begin=beginAddress;
      end=endAddress;
      current=head;
  }
  public Partition(int beginAddress,int endAddress){
      current=new PartitionNode(beginAddress,endAddress);
  
  }
  public void addProcess(int size,int id){
      if((current.endAddress-current.beginAddress&gt;=size)&amp;&amp; current.holeFree==true){
          newPartition=new PartitionNode(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   PartitionNode refresh(){
      current=new PartitionNode(newPartition.endAddress+1,end);
          return current;
  
  }
  public void deleteProcess(int process){
      PartitionNode 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);
  }
  
  
  }
  </code></pre>
  
  <p>I have two questions.<br>
  I have to have a constructor as </p>
  
  <pre><code>public Partition(int beginAddress,int endAddress,int a){
          head=new PartitionNode(beginAddress,endAddress);
          begin=beginAddress;
          end=endAddress;
          current=head;
      }  
  </code></pre>
  
  <p>where <strong>int a</strong> is of no use.It is just there to make sure that this constructor's argument list is different from</p>
  
  <pre><code> public Partition(int beginAddress,int endAddress){
          current=new PartitionNode(beginAddress,endAddress);
  
      }    
  </code></pre>
  
  <p>Because of this now I have to call as <code>Partition p=new Partition(300,3000,1);</code> with <strong>1</strong> being useless.<br>
  How can I get rid of this problem.   </p>
  
  <p>My next question is implementing method to  delete a process.  </p>
  
  <pre><code>public void deleteProcess(int process){
          PartitionNode temp=head;
  
          while(temp.next!=null){
              System.out.println(temp.processId);
              temp=temp.next;
  
          }
  
      }  
  </code></pre>
  
  <p>The while loop doesn't get executed.What's wrong with that?  </p>
  
  <p>Can someone please help me to correct the mistakes?</p>