Hi ppl I would really appreciate if someone help me out here. I really tried to do this problem and its driving me crazy. All I could get is the algorithum of worst fit, best-fit next fit and first fit. Please help me as soon as I can. And I will help ppl with anything I can.


Thanks

The problem it to implement first fit, best fit next fit and worst fit
1. must input mem size and the number and sizes of all the partitions
all the partitions (limit the max num of the partitions to 5)
2. for each partition you should create a descriptor with at least the following info.
partition size;
partition num;
partition status (free/busy)
size of unused space("hole")
job name (ex: j01 or j15)

input the job list that includes
job name;
job size

I just know the algorithum I really can't put the prog together if you can help me plllease i would really apreciate :)

I really can't compile this since it gives me some type of error. And also please can you help me out put it together I really need help putting it together Many thanks ...

Attachments
#pragma warning(disable: 4786)

#ifndef _FREE_LIST_H_
#define _FREE_LIST_H_

#include <iostream>
#include <list>

// ===========================================
// class node
// ===========================================
class node
{
public:
	node();
	node(int, int);
	node(const node &);
	~node() {}

	void SetSize(int);
	void SetOffset(int);

	int GetSize() const;
	int GetOffset() const;

	void operator = (const node &);
	bool operator == (const node &);
	bool operator != (const node &);
	bool operator < (const node &);
	bool operator > (const node &);
	bool operator <= (const node &);
	bool operator >= (const node &);
private:
	int size;
    int offset;
};

std::ostream & operator << (std::ostream &, node &);

// ===========================================
// class free_list
// ===========================================

// free_list constants

namespace fl_const
{
	const int DEFAULT_SIZE = 9900;
	const int DEFAULT_OFFSET = 0;
};

typedef std::list<node>::iterator fl_itr;

class free_list
{
public:
	free_list();
	free_list(int, int);
	~free_list() {}

	fl_itr GetBegin();
	fl_itr GetEnd();

	size_t Size() const;

	int f_malloc(int, int);				// allocate memory (returns offset)
	void f_dmalloc(int, int);			// deallocate memory

	void add_fl(node &);				// add a node to free list
	void delete_fl(node &);				// remove a node from free list

	int FirstFit(int);					// allocates memory using first fit
	int NextFit(int);					// allocates memory using next fit
	int BestFit(int);					// allocates memory using best fit
	int WorstFit(int);					// allocates memory using worst fit

	void Resize(size_t);				// resize free list
	void CombineNodes();				// combine adjacent nodes
private:
	std::list<node> f_list;
};

std::ostream & operator << (std::ostream &, free_list &);

#endif

Hello,

I have viewed and compiled the source files without warnings or errors with Visual C++ .Net 2003. I did not see main() declared in either of your two files, as I added it manually during my build. Would you mind sharing the precise error and what's your current compiler?


- Stack Overflow

Hello,

I have viewed and compiled the source files without warnings or errors with Visual C++ .Net 2003. I did not see main() declared in either of your two files, as I added it manually during my build. Would you mind sharing the precise error and what's your current compiler?


- Stack Overflow

This is the error I receive when I compile is the following..
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/mem-.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

mem-.exe - 2 error(s), 0 warning(s).

I use microsoft visual c++ version 6.0

Hello,

An unresolved external occurs when some code has a call to a function in another module and the linker can't find that function in any of the modules or libraries that you are currently linking to.

In this specific case, it means one of two things. Either you are trying to write a Win32 GUI application (or non-console application) and accidently compiled it as a Console application... or you really are trying to compile a console application and didn't write or properly compile in a main() function.

P.S. Make sure your program has an entry point, i.e. main()

A basic implementation of a program entry point in C++ is the following:

int main(void) {
	return 0;
}

- Stack Overflow

Hello,

An unresolved external occurs when some code has a call to a function in another module and the linker can't find that function in any of the modules or libraries that you are currently linking to.

In this specific case, it means one of two things. Either you are trying to write a Win32 GUI application (or non-console application) and accidently compiled it as a Console application... or you really are trying to compile a console application and didn't write or properly compile in a main() function.

P.S. Make sure your program has an entry point, i.e. main()

A basic implementation of a program entry point in C++ is the following:

int main(void) {
	return 0;
}

- Stack Overflow

Didn;t really resolve my prb actually now I have 52 erros can you copy and paste your version with no erros please

Hello,

Attached is a modified version of your main file: main.cpp

My workspace contains 1 Source File, main.cpp, and 1 Header File, free_list.h.


- Stack Overflow

Attachments
#include "free_list.h"
#include <iostream>

node::node()
{
	SetSize(0);
	SetOffset(0);
}

node::node(int n_size, int n_offset)
{
	SetSize(n_size);
	SetOffset(n_offset);
}

node::node(const node & n)
{
	SetSize(n.GetSize());
	SetOffset(n.GetOffset());
}

void node::SetSize(int s)
{
	size = s;
}

void node::SetOffset(int o)
{
	offset = o;
}

int node::GetSize() const
{
	return size;
}

int node::GetOffset() const
{
	return offset;
}

void node::operator = (const node & right)
{
	SetSize(right.GetSize());
	SetOffset(right.GetOffset());
}

bool node::operator == (const node & right)
{
	return GetOffset() == right.GetOffset();
}

bool node::operator != (const node & right)
{
	return GetOffset() != right.GetOffset();
}

bool node::operator < (const node & right)
{
	return GetOffset() < right.GetOffset();
}

bool node::operator > (const node & right)
{
	return GetOffset() > right.GetOffset();
}

bool node::operator <= (const node & right)
{
	return GetOffset() <= right.GetOffset();
}

bool node::operator >= (const node & right)
{
	return GetOffset() >= right.GetOffset();
}

std::ostream & operator << (std::ostream & out, node & n)
{
	using namespace std;
	out << "NODE" << endl;
	out << "SIZE: " << n.GetSize() << " OFFSET: " << n.GetOffset() << endl;
	return out;
}

free_list::free_list()
{
	using namespace fl_const;
	node * new_node = new node(DEFAULT_SIZE,DEFAULT_OFFSET);
	f_list.resize(0);
	f_list.push_back(*new_node);
	delete new_node;
}

free_list::free_list(int size, int offset)
{
	node * new_node = new node(size,offset);
	f_list.resize(0);
	f_list.push_back(*new_node);
	delete new_node;
}

fl_itr free_list::GetBegin()
{
	return f_list.begin();
}

fl_itr free_list::GetEnd()
{
	return f_list.end();
}

size_t free_list::Size() const
{
	return f_list.size();
}

int free_list::f_malloc(int size, int fit)
{
	switch (fit)
	{
	case 1:
		return FirstFit(size);
		break;
	case 2:
		return NextFit(size);
		break;
	case 3:
		return BestFit(size);
		break;
	case 4:
		return WorstFit(size);
		break;
	default:
		return FirstFit(size);
		break;
	}
}

void free_list::f_dmalloc(int size, int offset)
{
	using namespace std;
	node * new_node = new node(size,offset);
	add_fl(*new_node);
	delete new_node;
	CombineNodes();
}

void free_list::add_fl(node & n)
{
	f_list.push_back(n);
}

void free_list::delete_fl(node & n)
{
	f_list.remove(n);
}

int free_list::FirstFit(int size)
{
	using namespace std;
	int offset = -1;
	fl_itr begin = f_list.begin();
	fl_itr end = f_list.end();

	for (; begin != end; ++begin)
	{
		if (begin->GetSize() >= size)
		{
			offset = begin->GetOffset();
			begin->SetOffset(begin->GetOffset()+size);
			begin->SetSize(begin->GetSize()-size);
			if (begin->GetSize() == 0)
				f_list.erase(begin);

			return offset;
		}
	}
	return offset;
}

int free_list::NextFit(int size)
{
	using namespace std;
	int current_offset = -1;
	fl_itr begin = f_list.begin();
	fl_itr end = f_list.end();
	fl_itr match = f_list.begin();

	for (; begin != end; ++begin)
	{
		if (begin->GetSize() >= size)
		{
			if (current_offset > -1)
			{
				current_offset = begin->GetOffset();
				begin->SetOffset(begin->GetOffset()+size);
				begin->SetSize(begin->GetSize()-size);
				if (begin->GetSize() == 0)
					f_list.erase(begin);
				return current_offset;
			}
			current_offset = begin->GetOffset();
			match = begin;
		}
	}
	if (current_offset > -1)
	{
		current_offset = match->GetOffset();
		match->SetOffset(match->GetOffset()+size);
		match->SetSize(match->GetSize()-size);
		if (match->GetSize() == 0)
			f_list.erase(match);
		return current_offset;
	}
	return current_offset;
}

int free_list::BestFit(int size)
{
	using namespace std;
	int offset = -1;
	fl_itr begin = f_list.begin();
	fl_itr end = f_list.end();
	fl_itr best = f_list.begin();

	for (; begin != end; ++begin)
	{
		if (begin->GetSize() >= size)
		{
			offset = begin->GetOffset();
			if (begin->GetSize() < best->GetSize())
				best = begin;
		}
	}
	if (offset > -1)
	{
		offset = best->GetOffset();
		best->SetOffset(best->GetOffset()+size);
		best->SetSize(best->GetSize()-size);
		if (best->GetSize() == 0)
			f_list.erase(best);
		return offset;
	}
	return offset;
}

int free_list::WorstFit(int size)
{
	using namespace std;
	int offset = -1;
	fl_itr begin = f_list.begin();
	fl_itr end = f_list.end();
	fl_itr worst = f_list.begin();

	for (; begin != end; ++begin)
	{
		if (begin->GetSize() >= size)
		{
			offset = begin->GetOffset();
			if (begin->GetSize() > worst->GetSize())
				worst = begin;
		}
	}
	if (offset > -1)
	{
		offset = worst->GetOffset();
		worst->SetOffset(worst->GetOffset()+size);
		worst->SetSize(worst->GetSize()-size);
		if (worst->GetSize() == 0)
			f_list.erase(worst);
		return offset;
	}
	return offset;
}

void free_list::Resize(size_t size)
{
	f_list.resize(size);
}

void free_list::CombineNodes()
{
	using namespace std;

	if (f_list.size() > 1)
	{
		f_list.sort();
		fl_itr current = f_list.begin();
		fl_itr next = f_list.begin();
		fl_itr end = f_list.end();

		++next;

		for (; next != end; ++next)
		{
			if ((current->GetOffset() + current->GetSize()) == (next->GetOffset()))
			{
				next->SetSize(current->GetSize() + next->GetSize());
				next->SetOffset(current->GetOffset());
				f_list.erase(current);
				current = next;
			}
			else
				++current;
		}
	}
}

std::ostream & operator << (std::ostream & out, free_list & fl)
{
	using namespace std;
	list<node>::iterator begin = fl.GetBegin();
	list<node>::iterator end = fl.GetEnd();

	for (; begin != end; ++begin)
		out << *begin << endl;
	return out;
}

int main(void) {
	return 0;
}

I really also need help with the question. Please I really tried but and tried to implement best fit worst fit next fit first fit but I dont know how to tackle the question .
The problem it to implement first fit, best fit next fit and worst fit
1. must input mem size and the number and sizes of all the partitions
all the partitions (limit the max num of the partitions to 5)
2. for each partition you should create a descriptor with at least the following info.
partition size;
partition num;
partition status (free/busy)
size of unused space("hole")
job name (ex: j01 or j15)

input the job list that includes
job name;
job size


PLease help out here... Thanks in advance

This article has been dead for over six months. Start a new discussion instead.