1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

efficient way of collating (mixing) two linked lists using C

Discussion in 'Embedded' started by s_subbarayan, Mar 3, 2005.

  1. s_subbarayan

    s_subbarayan Guest

    Dear all,
    1)In one of our implementation for an application we are supposed to
    collate two linked lists.The actual problem is like this:

    There are two singularly linked lists, the final output will be a
    "perfectly shuffle" of the lists together into a single list. The new
    list should consist of consecutively alternating nodes from both
    lists.Note that both these linked lists have same kind of data
    structure in their nodes.

    The logic which I thought for implementing this is to create temporary
    node which resembles the nodes in the input linked lists and then copy
    second node into it,swap the pointers to insert the second lists first
    node into the first lists second node and proceed so on recursively by
    inserting the second lists node in between the first lists node.

    Is my thinking correct?I believe this is not that efficient way of
    doing it.Can some one let me know how effectively should we implement
    this collation between two linked lists?

    2)I came across the following code snippet regarding linked lists:
    struct _tagElement
    int m_cRef;
    unsigned char m_bData[20];
    struct _tagElement * m_next;

    } NODE, * PNODE;

    PNODE DoesWhat (PNODE pn1, PNODE pn2)
    PNODE * ppnV = &pn1;
    PNODE * ppn1 = &pn1;
    PNODE * ppn2 = &pn2;

    for ( ; *ppn1 || *ppn2; ppn1 =
    if (!(*ppn1) || (0 <
    memcmp((*ppn1)->m_bData, (*ppn2)->m_bData,
    PNODE pn = *ppn1;
    *ppn1 = *ppn2;
    pn2 = (*ppn2)->m_next;
    (*ppn1)->m_next = pn;
    return *ppnV;
    I inferred from this code,that the actual functionality of the function
    "DoesWhat" is to collate two linked list as stated in query (1)
    referred in this post.But my friend disagrees.I said that the function
    doeswhat takes first node of two linked lists(pn1 is first node of
    linkedlist1,pn2 is first node of linkedlist2-This is my assumption(need
    not be correct!)),and the code inside inserts nodes of list2 into nodes
    of list1,also the list will be sorted in increasing order of number of
    characters present in the array m_bData.
    Is my understanding and assumption regarding the input params for
    function "doeswhat" correct?Note that I dont have full code with me,so
    this code puzzled me,so I have to make it out myself!.

    Sorry if it looks too immature to ask,but I thought better learn now
    then never.I wish I am able to prove to my friend that I am
    correct,though I am ready to accept my fault incase I am disproved with
    proper proof.

    I appologise incase this OT.Please refer me to proper group incase this
    is OT.

    Looking farward to all your replys and advanced thanks for the same,
    s_subbarayan, Mar 3, 2005
    1. Advertisements

  2. s_subbarayan

    CBFalconer Guest

    Answer deleted due to later discovery that the OP multi-posted the
    same query on at least one other newsgroup. This obnoxious
    behaviour should not be rewarded.
    CBFalconer, Mar 3, 2005
    1. Advertisements

  3. s_subbarayan

    Dave Guest

    The self appointed usenet police.

    Yes I top posted to annoy you.
    Dave, Mar 3, 2005
  4. s_subbarayan

    CBFalconer Guest

    Good b....LONK.
    CBFalconer, Mar 3, 2005
  5. s_subbarayan

    Joe Guest

    Did you have a bad day (or something?) and just do the usenet equivalent of
    'going postal' on the OP?
    Joe, Mar 3, 2005
  6. The insistence on posting to one-and-only-one newsgroup is
    a bit anal. Unless the objection is to the multi-post, rather
    than appropriately cross-posting. But never attribute to
    obnoxiousness what can be reasonable explained by ignorance.

    The status can be upgraded to obnoxious upon discovery this
    is not the OP's first offense...

    Rufus V. Smith, Mar 3, 2005
  7. What's obnoxious about it?

    Richard Henry, Mar 3, 2005
  8. s_subbarayan

    CBFalconer Guest

    Having the same message come up and waste my (and others) time and
    storage in multiple newsgroups. This is what cross-posting is for,
    to attract attention from a variety of areas, PROVIDED that
    follow-ups are immediately set to concentrate the answers in a
    single group. Cross-posting without follow ups is bad,
    multi-posting is bad, top-posting is bad, and failure to snip is

    I found the multi-post on at least three newsgroups that I
    monitor. That means he probably did it to many more. I see no
    reason why usenet posters should not read and absorb some of the
    literature available on netiquette and usage.

    I will confess to feeling somewhat peckish when I posted that
    reply. But why should I go out of my way to help someone who comes
    across as too careless to observe the proprieties? At least I did
    him the courtesy of telling him WHY I am ignoring him.
    CBFalconer, Mar 3, 2005
  9. s_subbarayan

    Jan Homuth Guest

    The correct group is: comp.lang.c or comp.lang.c.moderated, I guess

    Your question sounds very much like a homework and it would be smart if
    you would lead the discussion with your friend (his name 'professor ? :) )
    to its end.
    Thereby learning...

    A very good reference for general wisdom on C :
    "The C Programming Language" by Kernighan & Ritchie

    Also consider to get Robert Sedgewick's "Algorithms in C"

    Jan Homuth, Mar 3, 2005
  10. s_subbarayan

    s_subbarayan Guest

    I have informed and even appologised if this post is OT.Further
    while I appreciate your comments in making this usenet clean I believe
    you can be polite and polished being an experienced professional.Simply
    bashing a poster will only discourage some one from using the usenet in
    a proper manner.While I agree that following few etiquettes is
    important,forget me,no one would like to get bashing from some
    unauthorised usenet controller.I believe only the moderator has right
    to say whats correct or whats wrong with a particular post!

    I posted this query in multiple groups jus to attract different
    opinion.Further In same group some time back I saw some one bashing for
    cross posting.In silence of moderator ubiquitous gurus sprang up and
    bash something making the discussion unhealthy!Had I cross posted I
    believe it could become more of a sort of debate on whose algorithm is
    best and viceversa which is not in my concern of the query.I feel if
    you are not interested you need not post your reply.There are many
    people who may be interested to reply.Further seeing the topic or query
    in the subject line one can easily judge whether the topic appeared in
    different group or not.Then I believe if you saw same post in some
    other group,you need not waste your time in reading it again and then
    waste your time and resources in bashing some poster like me.While you
    advice others it will be helpful if you follow what you advice
    regarding time.There are many people out there who are not visiting
    multiple groups,so I can get various replys from those people.
    On a softer note,please avoid bossy attitude.Everyone is a learner and
    there are lot to know.Known is a drop,unknown is a ocean!The query I
    posted is not meant to waste someones time!Its meant for a healthier
    discussion.But rather you moved away from crux of the problem!

    s_subbarayan, Mar 4, 2005

  11. Hello Subba,
    enappa idu ena ayichi??
    prashanth b s, Mar 4, 2005
  12. s_subbarayan

    CBFalconer Guest

    This is an unmoderated group, as are the others on which I found
    your posts. Only you know where you actually posted, so only you
    can set up a proper cross-posting with follow-ups set.

    I am not feeling quite as mean today as I was then. The objective,
    as ever, is to educate the newbies on usenet so that they don't do
    these foolish things. I notice you still did not quote any
    material to which you are replying, and have ignored the advice in
    my sig. below. This does not bode well for your ability to learn.
    CBFalconer, Mar 4, 2005
  13. s_subbarayan

    s.subbarayan Guest

    Its good to know you are interested in educating the newby users of
    usenet.But I believe there are better ways of educating from the
    approach what you have taken.Looks like bashing to me or any one who
    reads this.I feel better way is to put anything you want to say in
    softer note then using harsh words like "foolishness" again in your
    reply.I believe more then being a professional its good if we are
    first of all good human beings.While you take interest in educating
    others,it will be better if you put things in proper way so people get
    it in right manner.You said I have not learnt to put reply,but it
    seems you too should be able to learn using polite soft words.By the
    way the problem why my reply message appeared to you like that(not
    following quote!) partly because of the problem with google.I still
    get the old version of usenet in my webpage which did not show any
    options what you have put in your quote!If only its updated I would be
    happy enough to follow good things if put in proper way!

    s.subbarayan, Mar 7, 2005
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.