Sunday, August 2, 2009

C program for creating simple single linked list??

A singly linked list will include a next pointer in the list data structure, along with whatever your list contains. My C is very rusty, and I haven;t compiled anything, but I'll take a whack:


So if I was doing a list of names, the structure could be





struct Names


{


char firstName[24];


char lastName[24];


Names * nextName;


} beginning;





Then I could have code like





struct Names beginning, middle, ending;





beginning.nextName = %26amp;middle;


middle.nextName = %26amp; ending;


ending.nextName = 0; // null terminate the list





Hmm, does the last example need to use null rather than 0? I can't recall. The compiler should tell you.





That would create a simple single linked list with 3 elements and room to store 1st %26amp; last names (up to 24 chars each) in each.


No comments:

Post a Comment