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;
    }
  • 相关阅读:
    kafka副本
    kafka消息丢失
    kafka消费者
    RN8302b调试笔记
    MDK #pragma anon_unions
    [Python笔记]Strip
    [Python笔记]AnyAll
    [Python笔记]元组
    [Python笔记]列表
    嵌入式平台移植Python
  • 原文地址:https://www.cnblogs.com/gsblog/p/3444305.html
Copyright © 2011-2022 走看看