Digital Stronghold - Software Engineering Blog




November 9, 2005

Creating a list by iteration

Filed under: Progressive Studies

The previous post is quite a bit confusing because it is by recursion. Well, nothing special. Here is the code in all its glory.

#include "list.h"
	
LINK s_to_l(char s[])
{
        LINK head = NULL, tail;
        int i;
	
        if (s[0] != '\0') {
                head = malloc(sizeof(ELEMENT));
                head -> d = s[0];
                tail = head;
	
                for (i = 1; s[i] != '\0'; ++i) {
                        tail -> next = malloc(sizeof(ELEMENT));
                        tail = tail -> next;
                        tail -> d = s[i];
                }
                tail -> next = NULL;
        }
	
        return head;
}

Comments »

The URI to TrackBack this entry is: http://eradicus.blogsome.com/2005/11/09/iterative-way-of-creating-a-linked-list/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Theme designed by Joset Anthony Zamora


Digital Stronghold

↑ Get Headline Animator