Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Standard C, C++

Reply
 
LinkBack Thread Tools Display Modes
Old 04-12-2003, 03:58 PM   #1 (permalink)
gqchynaboy
Registered User
 
Join Date: Apr 2003
Posts: 4
gqchynaboy is on a distinguished road
What do these Methods do? Take a look please

Can anyone help me and tell me what Method1, Method2, Method3, Method4, Method5 do?


template <class T>
bool List<T> ::Method1 (const T & value)
{
if (used == capacity)
if(Method5 (capacity + CHUNK) ==false)
return false;
if (first == -1)
first = last = 0;
else if (first == 0)
first = capacity -1;
else
first --;
data[first] = value;
used++;
return true;
}

template <class T>
bool List<T> ::Method2 (const T & value)
{
if (used == capacity)
if(Method5 (capacity + CHUNK) ==false)
return false;
if (last == -1)
first = last = 0;
else
last = (last +1) % capacity;
data[first] = value;
used++;
return true;
}

template <class T>
bool List<T> ::Method3 ( T & value)
{
if (used ==0)
return false;
value = data[first];
if(capacity - used >= 1.5 * CHUNK)
if(Method5 (capacity + CHUNK) ==false)
return false;
used--;
if (used ==0)
first = last = -1;
else
first = (first +1) % capacity;
return true;
}

template <class T>
bool List<T> ::Method4 ( T & value)
{
if (used ==0)
return false;
value = data[first];
if(capacity - used >= 1.5 * CHUNK)
if(Method5 (capacity + CHUNK) ==false)
return false;
used--;
if (used ==0)
first = last = -1;
else if (last ==0)
last = capacity -1;
else
last --;

return true;
}



template <class T>
bool List<T> ::Method5 (const size_t & new_capacity)
{
T * temp = data;
data = new T[new_capacity];
if(data == NULL)
{
data = temp;
return false;
}
if (used >0)
{
int j =first;
int k = (new_capacity - used) /2;
first =k;
last = first + used -1;
for (int i =0; i <used ; i++)
{
data[k] = temp[j];
j = (j+1) % capacity;
k++;
}
}
capacity = new_capacity;
delete []temp;
return true;
}
gqchynaboy is offline   Reply With Quote
Old 04-14-2003, 10:00 PM   #2 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
the only people who name their functions "Method1", "Method2", etc. are idiots and teachers/professors.

no, we will not do your homework for you.
joe_bruin is offline   Reply With Quote
Old 04-15-2003, 11:45 AM   #3 (permalink)
Moral_Hazard
Registered User
 
Moral_Hazard's Avatar
 
Join Date: Apr 2003
Posts: 2
Moral_Hazard is on a distinguished road
LMAO!!!!! :th:
Moral_Hazard is offline   Reply With Quote
Old 04-15-2003, 02:27 PM   #4 (permalink)
carrja99
Registered User
 
Join Date: Feb 2003
Posts: 34
carrja99 is on a distinguished road
Any idiot off the street could figure those out (although they may have trouble reading it without code tags).

As stated previosuly... no, we will not do your homework for you.
carrja99 is offline   Reply With Quote
Old 04-15-2003, 03:06 PM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
hmmm.. I actualy started reading them, then I realised I couldn't keep up with where I was at, without the proper indentation and just left it as it was.... btw, what value is capacity and new_capacity initialised as??

I think I have that problem noticed in one of my C++ books as an exersize for the reader...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-15-2003, 03:59 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
hehe, i was gonna put the code tags in, but i saw that the original post wasn't indented .. oh well.
__________________
Mike
sde is offline   Reply With Quote
Old 04-15-2003, 07:11 PM   #7 (permalink)
gqchynaboy
Registered User
 
Join Date: Apr 2003
Posts: 4
gqchynaboy is on a distinguished road
Code:
template <class T>
bool List<T> ::Method1 (const T & value)
{
	if (used == capacity)
			if(Method5 (capacity + CHUNK) ==false)
				return false;
	if (first == -1)
			first = last = 0;
	else if (first == 0)
		first = capacity -1;
	else
		first --;
	data[first] = value;
	used++;
	return true;
}

template <class T>
bool List<T> ::Method2 (const T & value)
{
	if (used == capacity)
			if(Method5 (capacity + CHUNK) ==false)
				return false;
	if (last == -1)
			first = last = 0;
	else 
		last = (last +1) % capacity;
	data[first] = value;
	used++;
	return true;
}

template <class T>
bool List<T> ::Method3 ( T & value)
{
		if (used ==0)
			return false;
		value = data[first];
		if(capacity - used >= 1.5 * CHUNK)
				if(Method5 (capacity + CHUNK) ==false)
					return false;
		used--;
		if (used ==0)
			first = last = -1;
		else
			first = (first +1) % capacity;
			return true;
}

template <class T>
bool List<T> ::Method4 ( T & value)
{
	if (used ==0)
			return false;
		value = data[first];
		if(capacity - used >= 1.5 * CHUNK)
				if(Method5 (capacity + CHUNK) ==false)
					return false;
	used--;
		if (used ==0)
			first = last = -1;
		else if (last ==0)
			last = capacity -1;
		else 
			last --;

		return true;
}



template <class T>
bool List<T> ::Method5 (const size_t & new_capacity)
{
	T * temp = data;
	data = new T[new_capacity];
	if(data == NULL)
	{
		data = temp;
		return false;
	}
	if (used >0)
	{
			int j =first;
			int k = (new_capacity - used) /2;
			first =k;
			last = first + used -1;
			for (int i =0; i <used ; i++)
			{
				data[k] = temp[j];
				j = (j+1) % capacity;
				k++;
			}
	}
	capacity = new_capacity;
	delete []temp;
	return true;
}
gqchynaboy is offline   Reply With Quote
Old 04-15-2003, 07:13 PM   #8 (permalink)
gqchynaboy
Registered User
 
Join Date: Apr 2003
Posts: 4
gqchynaboy is on a distinguished road
Method 1 “InsertFirst”
If there is no space, Method 5 is called to create new space.
In addition, Method 1 adds integers to the beginning of the list.

Method 2 “InsertLast”
If there is no space, Method 5 is called to create new space.
In addition, Method 2 adds integers to the end beginning of the list.

Method 3 “RemoveFirst”
If there is no space, Method 5 is called to create new space.
In addition, Method 3 removes the integers from the beginning of the list.

Method 4 “RemoveLast”
If there is no space, Method 5 is called to create new space.
In addition, Method 4 removes the last integers of the list

Method 5 “AddSpace”

Am i right??
gqchynaboy is offline   Reply With Quote
Old 04-15-2003, 09:06 PM   #9 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
you're right about everything except about the word "integers". this template can work on whatever datatype you declare it as.
joe_bruin is offline   Reply With Quote
Old 04-15-2003, 10:07 PM   #10 (permalink)
gqchynaboy
Registered User
 
Join Date: Apr 2003
Posts: 4
gqchynaboy is on a distinguished road
oh yea
When Method 5 is called, it allocates more memory.
gqchynaboy is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
to put data methods inside class or not? sde Java 2 05-25-2004 05:09 PM
Methods of moving a database... DarkTwilkitri PHP 8 11-19-2003 06:02 AM


All times are GMT -8. The time now is 03:01 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting