Click here to Skip to main content
15,915,019 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Plugin question Pin
Cedric Moonen28-Jun-05 22:04
Cedric Moonen28-Jun-05 22:04 
GeneralRe: Plugin question Pin
Steve Messer28-Jun-05 22:15
Steve Messer28-Jun-05 22:15 
GeneralLibrary Conflict Pin
MK7828-Jun-05 21:34
MK7828-Jun-05 21:34 
GeneralRe: Library Conflict Pin
oustar29-Jun-05 0:04
oustar29-Jun-05 0:04 
GeneralRe: Library Conflict Pin
Blake V. Miller29-Jun-05 19:05
Blake V. Miller29-Jun-05 19:05 
QuestionCan CSocket comunicate with the Palm Client? Pin
javaClaude28-Jun-05 21:30
javaClaude28-Jun-05 21:30 
AnswerRe: Can CSocket comunicate with the Palm Client? Pin
GDavy28-Jun-05 23:04
GDavy28-Jun-05 23:04 
GeneralLinked list Pin
LiYS28-Jun-05 21:28
LiYS28-Jun-05 21:28 
I'm doing a little exercise after reading some chapter, it's about linked list, here is the description.
Create a struct that holds an int and a pointer to another
instance of the same struct. Write a function that takes
the address of one of these structs and an int indicating
the length of the list you want created(in my case: initialize). This function will make a whole chain of these structs (a linked list), starting
from the argument (the head of the list), with each one
pointing to the next. Make the new structs using new,
and put the count (which object number this is) in the int.
In the last struct in the list, put a zero value in the pointer
to indicate that it抯 the end. Write a second function(print) that
takes the head of your list and moves through to the end,
printing out both the pointer value and the int value for
each one.

After think for a while, I'm came up with a solution, but not a completed one.
The codes goes like this:

struct link<br />
{<br />
int a;<br />
link *next;<br />
};<br />
<br />
void initialize(link * head, int nCount)<br />
{<br />
	head->a = 0;<br />
	head->next = new link;<br />
	link *tmp = head->next;<br />
	tmp->a = 1;<br />
	for (int i = 2; i < nCount; i++)<br />
	{<br />
		link *lnk = new link;<br />
		tmp->next = lnk;<br />
		lnk->a = i;<br />
		tmp = tmp->next;<br />
	}<br />
}<br />
<br />
void print(link *head)<br />
{<br />
while (head->next) <br />
{<br />
cout << head->a << endl;<br />
head = head->next;<br />
}<br />
}<br />
<br />
int main()<br />
{<br />
link *head = new link;<br />
initialize(head, 10);<br />
print(head);<br />
}

I wonder how should I implement the initialize(...)?
GeneralRe: Linked list Pin
Yulianto.28-Jun-05 21:47
Yulianto.28-Jun-05 21:47 
GeneralRe: Linked list Pin
LiYS28-Jun-05 21:57
LiYS28-Jun-05 21:57 
GeneralRe: Linked list Pin
Yulianto.28-Jun-05 22:05
Yulianto.28-Jun-05 22:05 
GeneralRe: Linked list Pin
LiYS28-Jun-05 22:14
LiYS28-Jun-05 22:14 
GeneralRe: Linked list Pin
Yulianto.28-Jun-05 22:19
Yulianto.28-Jun-05 22:19 
GeneralRe: Linked list Pin
LiYS30-Jun-05 16:59
LiYS30-Jun-05 16:59 
GeneralRe: Linked list Pin
LiYS28-Jun-05 22:43
LiYS28-Jun-05 22:43 
GeneralRe: Linked list Pin
Yulianto.28-Jun-05 22:56
Yulianto.28-Jun-05 22:56 
GeneralRe: Linked list Pin
John R. Shaw29-Jun-05 8:19
John R. Shaw29-Jun-05 8:19 
GeneralRe: Linked list Pin
David Crow30-Jun-05 3:47
David Crow30-Jun-05 3:47 
GeneralRe: Linked list Pin
LiYS30-Jun-05 17:00
LiYS30-Jun-05 17:00 
GeneralEmbedding tiff in pdf Pin
Chathan28-Jun-05 21:18
Chathan28-Jun-05 21:18 
GeneralProgramFiles Pin
sunit528-Jun-05 21:15
sunit528-Jun-05 21:15 
GeneralRe: ProgramFiles Pin
oustar29-Jun-05 0:14
oustar29-Jun-05 0:14 
GeneralRe: ProgramFiles Pin
David Crow30-Jun-05 3:50
David Crow30-Jun-05 3:50 
QuestionOpening files within a webview without download dialog? Pin
retro_coder28-Jun-05 20:53
retro_coder28-Jun-05 20:53 
GeneralBio- Powered DLL ?? :o Pin
_kane_28-Jun-05 20:36
_kane_28-Jun-05 20:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.