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++
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 04-12-2003, 02: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, 09: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, 10: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, 01: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, 02:06 PM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,680
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, 02:59 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
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.
__________________
testing 1 2 3
sde is offline   Reply With Quote
Old 04-15-2003, 06: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, 06: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, 08: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, 09: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


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

vB 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 04:09 PM
Java Class Basics: Static Methods bdl Java 0 02-29-2004 02:25 PM
Methods of moving a database... DarkTwilkitri PHP 8 11-19-2003 05:02 AM
The Math object anon Javascript 0 02-24-2003 01:46 PM
Logging into a Password Protected Site technobard Java 0 02-24-2003 01:19 PM


All times are GMT -8. The time now is 06:31 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle