Write a program that simulates the “heap” using a linked list. This program should
take one node of size 9096 kb. Assume all request will be made in kb. The user
should request a size of memory from the system, then the system should find
memory that can be allocated based on the user’s request. If memory cannot be
allocated based on the user request, send the appropriate message. Memory should
be returned back to the system after it is freed.

My freeAllSpace function causes the program to crash...
It is suppose to delete the headUFS linked list and it is suppose to
delete all but the first node on the headFS link list.
#include <iostream>
using namespace std;

struct node
     int data;
     node *next;

void freeAllSpace(node *,node *);

int main()
     node *headFS = NULL;
     int space = 9096;
     headFS = new node;
     int requestedMEM=-1;
     int temp = 0;
	 int a;

     node *headUFS = NULL;
     headUFS = new node;

     node *previousUFS = NULL;
     previousUFS = new node;

     while(headFS->data>0 && requestedMEM<headFS->data && requestedMEM!=0)
          cout<<"How much memory would you like?";

          cout<<"No memory requested."<<endl;

          else if(headFS->data<0 || requestedMEM>headFS->data)
               cout<<"There is not enough free space left."<<endl;

               headUFS->data = temp;
               previousUFS->data = temp;
               a = headFS->data - previousUFS->data;
			   headFS->data =a;
     cout<<"Total Free Space: "<<headFS->data<<endl;
     cout<<"Total Used Space: "<<headUFS->data<<endl;

     return 0;

void freeAllSpace(node *headFS, node *headUFS)
	node *temp2;
	node *temp3;

    cout<<"Freeing all space."<<endl;

		temp2 = headUFS;
		headUFS = headUFS->next;
		delete temp2;

		temp3 = headFS;
		headFS = headFS->next;
		delete temp3;

	cout<<"Total Free Space: "<<headFS->data<<endl;
This article has been dead for over six months. Start a new discussion instead.