📜  遍历链表 - C 编程语言代码示例

📅  最后修改于: 2022-03-11 15:04:40.536000             🧑  作者: Mango

代码示例1
#include
#include

//1
typedef struct node{
    int value;
    struct node *next;
}node;


int main(){
    int length,i;

    //2
    printf("Enter size of the list : ");
    scanf("%d",&length);

    //3
    struct node *headNode, *currentNode, *temp;

    //4
    for(i=0 ; ivalue);

        //7
        if(i==0){
            headNode = temp = currentNode;
        }else{
            //8
            temp->next = currentNode;
            temp = currentNode;
        }
    }

    //9
    temp->next = NULL;

    //10
    temp = headNode;

    //11
    printf("Iterating through the elements of the linked list : \n");
    while(temp != NULL){
        //12
        printf("%d \n",temp->value);
        temp = temp -> next;
    }
}