User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,905 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,319 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1806 | Replies: 8
Reply
Join Date: Dec 2004
Posts: 21
Reputation: helloworld is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
helloworld helloworld is offline Offline
Newbie Poster

queue , memory, 32k please

  #1  
Jan 5th, 2005
please help me, am confused in the memory bit, all i want is 32 k memory free and each time i add something and run it, it will say for example 27 k memory left

how to i make this program only have 32 k memory, for example At the beginning there will be no notthing running and none in the queue so the screen might show something like this:

32k free
none running:
-------------------------------------------------

Then 1 might enter the queue ( jobs start in the queue and then are chosen to execute ie they have to be in the queue first). The screen might look like this:

32k free
jobs running:

-------------------------------------------------

jobs in queue:

job 1 8 k p3



Suppose another job joins the queue:

32k free
jobs running:

-------------------------------------------------

jobs in queue:

job 1 8 k p3
job 2 4k p1


Then the operator decides to start job 2:

28k free
jobs running:

job 2 4k p1
-------------------------------------------------


jobs in queue:

job 1 8 k p3


Next job 1 is started:

20k free
jobs running:

job 2 4k p1
job 1 8 k p3
-------------------------------------------------
jobs in queue:

Then the operator halts job 2:

28k free
jobs running:

job 1 8 k p3

-------------------------------------------------

jobs in queue:



// Program to demonstrate a queue using nodePtrs
// The size of the queue is limited only by the
// amount of dynamic RAM available

#include <iostream.h>
#include <stdlib.h>


struct node;
typedef node *nodePtr;

struct node
{
	char data;
	nodePtr next;
};

struct queue
{
	nodePtr front;
	nodePtr rear;
};


void create(queue&);
bool empty(queue);
bool full();
void addToQueue(queue&, char);
void deleteFromQueue(queue&, char&);
void traverseQueue(queue);


void create(queue& Q)
{
	Q.front = NULL;
	Q.rear = NULL;
}


bool empty(queue Q)
{
	if(Q.front == NULL)
		return true;
	else
		return false;
}

bool full()
{
	nodePtr temp =new node;

	if (temp == NULL)
		return true;
	else
	{
		delete temp;
		return false;
	}
}

void addToQueue(queue& Q, char item)
{
		nodePtr temp;

		temp = new node;
		temp->data = item;
		temp->next = NULL;

		if (Q.front != NULL) // ie not empty
		{
			Q.rear->next = temp;
			Q.rear = temp;
		}
		else
		{
			Q.front = temp;
			Q.rear = temp;
		}
}

void deleteFromQueue(queue& Q, char& item)
{
	nodePtr temp;

	if (Q.front != NULL)      // ie not empty
	{
		temp = Q.front;
		item = temp->data;

		if (Q.rear == Q.front) // ie single node so queue becomes empty
		{
			Q.front = NULL;
			Q.rear = NULL;
		}
		else                  // more than one node
			Q.front = temp->next;

   	delete temp;
	}
}

void traverseQueue(queue Q)
{
	nodePtr temp;

	temp = Q.front;

	while (temp != NULL)
		{
		cout << temp->data << endl;
		temp =  temp->next;
		}
}

void main()
{
	queue q;
	char command, letter;

	create(q);
	system("cls");

	cout << "This program uses a queue implemented using pointers\n";
	cout << "The number of items in the queue is only limited by\n";
	cout << "amount of dynamic RAM available\n";

	do
	{
		cout << "\n[A]dd to queue, [D]elete from queue, [P]rint queue, "  ;
		cout << "or [Q]uit -> ";
		cin >> command;
		switch(command)
		{
			case 'a' :
			case 'A' :  cout << "Enter data -> ";
						cin >> letter;
						addToQueue(q, letter);
						break;
			case 'd' :
			case 'D' :  if (!empty(q))
						{
							deleteFromQueue(q, letter);
							cout << letter << " removed from queue\n";
						}
						else
							cout << "The queue is empty \n";
						break;
			case 'p' :
			case 'P' :  traverseQueue(q);
						break;
			case 'q' :
			case 'Q' : 	cout << "Program terminated\n";
						break;
			default  :	cout << "Unknown command [" << command << "] try again!\n";
			}	// end switch
	 } while (!(command == 'q' || command == 'Q'));
}
Last edited by alc6379 : Jan 5th, 2005 at 4:38 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Posts: 21
Reputation: helloworld is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
helloworld helloworld is offline Offline
Newbie Poster

Re: queue , memory, 32k please

  #2  
Jan 5th, 2005
i need example, i need the code, as soon as possible
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 11
Solved Threads: 102
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: queue , memory, 32k please

  #3  
Jan 5th, 2005
Originally Posted by helloworld
i need example, i need the code, as soon as possible

That's nice. I need a new car, I need the vehicle, as soon as possible. Let's both sit here and wait to see who gets one first.

It's okay to post a question like this, as you've shown some effort, but it's still considered rude to insist that someone help you ASAP when others have been here before you, waiting patiently.
Alex Cavnar, aka alc6379
Reply With Quote  
Join Date: Dec 2004
Posts: 21
Reputation: helloworld is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
helloworld helloworld is offline Offline
Newbie Poster

Re: queue , memory, 32k please

  #4  
Jan 6th, 2005
the reason i need help is beccause i need to hand it in soon, that why
Reply With Quote  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 11
Solved Threads: 102
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: queue , memory, 32k please

  #5  
Jan 6th, 2005
Originally Posted by helloworld
the reason i need help is beccause i need to hand it in soon, that why

I know.

But, instead of posting it to a forum, get to coding. Someone here might be able to help you, but I'm focused on how your post seemed to convey a sense of urgency that we're not required to share here.

We're a free help forum. If we don't help you in time, you got what you paid for.
Alex Cavnar, aka alc6379
Reply With Quote  
Join Date: Dec 2004
Posts: 21
Reputation: helloworld is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
helloworld helloworld is offline Offline
Newbie Poster

Re: queue , memory, 32k please

  #6  
Jan 6th, 2005
do you know anything about c++. or have you just created this site for fun. i though you people knew certain things, i guess i was wrong. how hard can it be for creating a my program
Reply With Quote  
Join Date: Dec 2004
Location: Devon - UK
Posts: 420
Reputation: 1o0oBhP is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 6
1o0oBhP's Avatar
1o0oBhP 1o0oBhP is offline Offline
Posting Pro in Training

Re: queue , memory, 32k please

  #7  
Jan 6th, 2005
how hard can it be for creating a my program
careful there! you couldnt do it either! What exactly is going wrong with it anyways? maybe we could give a hint if we know what is wrong?
http://sales.carina-e.com

no www
no nonsense

coming soon to a pc near you! :cool:
Reply With Quote  
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation: Chainsaw is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 9
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: queue , memory, 32k please

  #8  
Jan 6th, 2005
the standard C runtime routines to allocate and free memory do not have a way to tell you how much the OS has free. On Windows you can use GlobalMemoryStatus(), but that talks about total OS memory including all swap space and the like. If you are using another OS, you may have to poke around in the help files or docs for that OS.

But, even on Windows there may be process-level restrictions, and actions by other programs on the system can change the amount of free memory from moment to moment.

If you wanted to SIMULATE this for some theoretical smaller machine, you could write some code to break up a block of ram (maybe the 32k you keep referring to) into chunks rather than using 'new' and 'delete', and you could accurately report on the size of THAT block of ram.

as to "how hard can it be for creating a my program", we're here for help but not here to do your work for you. And we do this for free on our spare time. When we want to, for whom we want to. If you are not happy with the service, feel free to go elsewhere.
Reply With Quote  
Join Date: Sep 2004
Posts: 6,330
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 28
Solved Threads: 458
Super Moderator
Narue's Avatar
Narue Narue is online now Online
Expert Meanie

Re: queue , memory, 32k please

  #9  
Jan 8th, 2005
do you know anything about c++. or have you just created this site for fun. i though you people knew certain things, i guess i was wrong. how hard can it be for creating a my program
Bahahahahahahaha! That's a good one. "Here's my homework, do it for me because I don't believe that you can". Haha, thanks for the laugh retard, now go crawl back into your hole until you can understand why we won't be your code monkeys so that you can get a free ride in your class.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:17 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC