home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2852
Discussions: 188,380, Posts: 2,243,462, Members: 232,608
Old October 29th, 2002, 01:11 AM   Digg it!   #1 (permalink)
ILC
Senior Member
 
ILC's Avatar
 
Join Date: Oct 2001
Location: Eastern Shore
Posts: 701
Help

Alright, let me try to explain things as clearly as possible.

I have created two classes, one is a Node class and the other is a set class. Now the set class is composed of Nodes, however, there is NOT any inheritance. (Creating a pointer-based linked list).

The Node member has only two data types, int dataValue (the data for that Node) and Node *next (a pointer to the next Node in the list).

Anywho, what I am trying to do is create a local function in the Set class that returns a Node. Can not seem to get the syntax correct though. Here is what I have so far
Code:
Node *current;
current=(head,members);
//head is the first member of the list, members is the number of members in the list

Node findLast(Node *pointer, int members)
{
	int i=1;
	while(i<members)
	{
		pointer=pointer->next;
		i++;
	}
	return pointer;
}
Very simple and straightforward function, the return is just killing me. Anyways, thanks you all.

ILC

ILC is offline   Reply With Quote
Old October 29th, 2002, 07:59 AM     #2 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
How's about
Code:
Node *current = findLast(head, members);
//head is the first member of the list, members is the number of members in the list

Node *findLast(Node *pointer, int members) {
    // note we iterate n-1 times as we start at node 0 and follow ->next n-1 times to node n-1
    for (int i = 1; i < members; i++)
        pointer = pointer->next;
    return pointer;
}

strangerstill is offline   Reply With Quote
Old October 29th, 2002, 11:01 AM     #3 (permalink)
ILC
Senior Member
 
ILC's Avatar
 
Join Date: Oct 2001
Location: Eastern Shore
Posts: 701
*Mouth drops*

Lol, I guess I had been working on this program too long. Completely forgot to call the function and could not figure out why it wouldn't work

Thanks stranger.

ILC

ILC is offline   Reply With Quote
Old October 29th, 2002, 09:23 PM     #4 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
hehe no probs
btw use for loops wherever possible/sensible - they're syntactic candy but useful & in general self-documenting candy
strangerstill is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may 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 Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2885)
The United States Debt (20)
Looks like Burris will get his Sena.. (8)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Help with an Ati Radeon HD 4850 512.. (25)
Recent Discussions
Building a gaming computer advi.. (0)
Best digital camera for under 2.. (14)
Help with an Ati Radeon HD 4850.. (25)
Install Problem for Windows Def.. (0)
New Build ( Finally ) (1)
dual monitors wont boot (0)
Folderchat Weekday thread (439)
MSN Hotmail Down??? (7)
Laptop waking up itself (0)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:42 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28