title: How can i add onto the linked list for best fit management or delete something?
body: <p>I am having trouble with linked list best fit memory management. I created the linked list and add the first element , but it does not add anything else after. It basically avoids my else statement. If anyone can give me a concept on how to do it or if i am doing anything wrong, it would be great if you let me know!</p>
  
  <pre><code>unsigned int MaxMem = 400000000;
  struct PCB
  {
      struct PCB *next;
      struct PCB *prev;
      int PID;
      unsigned int PrSize;
      int best;
      unsigned int Begin;
      unsigned int End;
  }*node = NULL, *first = NULL, *node1 = NULL, *node2 = NULL;
  class linked
  {
      public:
  
          void Mem_begin(PCB a)
          {
              PCB *add = new PCB;
              struct PCB *save;
              int bestfit = -1;
              //add-&gt;End = MaxMem;
              add-&gt;Begin = a.PrSize;
              add-&gt;next = NULL;
              if((first == NULL) &amp;&amp; (bestfit1 == -1))
              {
                  bestfit = a.ProcessID;
                  a.best = bestfit;
                  add-&gt;prev = NULL;
                  first = add;
                  cout &lt;&lt; first-&gt;prev &lt;&lt; " - " &lt;&lt; first-&gt;Begin &lt;&lt; " Process " &lt;&lt; bestfit &lt;&lt; endl;
              }
              else
              {
                  save = first;
                  while(save-&gt;prev != NULL)
                  {
                      bestfit = a.PID;
                      a.best = bestfit;
                      save = save-&gt;next;
                      save-&gt;next = add;
                      add-&gt;prev = save;
                      cout &lt;&lt; " i did it" &lt;&lt; endl;
                  }
  
              }
          }
  
          void display(PCB a) {
              node = first;
              while(node != NULL)
              {
                  cout &lt;&lt; node-&gt;prev &lt;&lt; " - " &lt;&lt; node-&gt;Begin &lt;&lt; " Process " &lt;&lt; a.best &lt;&lt; endl;
                  node = node-&gt;next;
              }
          }
  };
  int main()
  {
      PCB test;
      linked try;
      while(true)
      {
          cout &lt;&lt; "What is the PID?" &lt;&lt; endl;
          cin &gt;&gt; test.PID;
          cout &lt;&lt; "How much memory space?" &lt;&lt; endl;
          cin &gt;&gt; test.PrSize;
          try.Mem_begin(test);
      }
   }
  </code></pre>