singly linked chain printing c++

后端 未结 6 503
刺人心
刺人心 2021-01-28 18:39

I am trying to pick my chain in the format {1,2,3,4,etc}. You can find the header file below which will have the layout of the nodes. I am just confused on how I should go about

6条回答
  •  暖寄归人
    2021-01-28 18:41

    Suppose your list is cyclical, you can use this:

    struct Node *n = begin;
    
    if (n != NULL) {
        //do something on it
        ...
        for (n = begin->Succ; n != begin; n = n->Succ) {
        }
    }
    

    or

    struct Node *n = begin;
    if (n != NULL) {        
        do {        
            //do something
            ...
            n = n->Succ;
        } while (n != begin)
    }
    

提交回复
热议问题