zoukankan      html  css  js  c++  java
  • List实现

    1、元素添加

    #include <stdio.h>
    #include <stdlib.h>
    
    struct ListNode{
        struct ListNode* next;
        int data;
    };
    
    typedef struct ListNode node;
    
    void AddFront(node** head,node* newnode){
        newnode->next = *head;
        *head = newnode;
    }
    
    void PrintList(node* head)                                                                                                                                   
    {
        node* cur = head;
    
        if(cur == NULL)
            printf("Empty List
    ");
        else{
    
         while(cur != NULL)
            {
                if(cur->next == NULL)
                    printf("%d
    ", cur->data);
                else
                    printf("%d->", cur->data);
                cur = cur->next;
    
            }
        }
    }
    
    int main()
    {
        node* head = NULL;
        int data;
    
        int a[] = {1,2,3,4,5};
        int len = sizeof(a)/sizeof(int);
        int i;
    
        for(i = 0;i < len; i++ ){
    
            data = a[i];
            node* newnode = (node*)malloc(sizeof(node));
    
            newnode->data = data;
            newnode->next = NULL;
            AddFront(&head,newnode);
    
        }
    
        PrintList(head);
        return 0;
    }
  • 相关阅读:
    Unable to load dbxmss.dll (ErrorCode 16). It may be missing from the system Path
    同一网内机器无法连通解决一例
    Day.24
    Day.24
    Day.23
    Day.22
    Day.23
    Day.21
    Day.22
    Day.01-Day.20
  • 原文地址:https://www.cnblogs.com/gsblog/p/3444305.html
Copyright © 2011-2022 走看看