zoukankan      html  css  js  c++  java
  • System 102: Review of Linked List & Bitwise Operation

    Example:

    #include <stdio.h>
    #include <stdlib.h>
    
    typedef struct node
    {
        int num;
        struct node *next;
    }Node;
    
    typedef struct my_list
    {
        Node *head;
        int count;
    }List;
    
    void print_list(List *list){
        Node *current = list->head;
    
        while(current != NULL){
            printf("%d\n",current->num);
            current = current->next;
        }
    }
    
    void insert_at_front(List *list, int num){
        Node* new_node = malloc(sizeof(Node));
        new_node->num  = num;
        new_node->next = list->head;
        list->head = new_node;
        list->count++;
    }
    /* index starting from 0 (rightmost) to 31 (leftmost) */
    int get_bit(int value, int index){ int retVal = (value>>index)&1; return retVal; } int clear_bit(int value, int index){ int mask = 1 << index; int retVal = value & ~mask; return retVal; } int main() { List *my_list = malloc(sizeof(List)); my_list->head = NULL; my_list->count = 0; print_list(my_list); insert_at_front(my_list, 1); insert_at_front(my_list, 2); insert_at_front(my_list, 3); insert_at_front(my_list, 4); print_list(my_list); return 0; }



     

  • 相关阅读:
    构建之法阅读笔记01
    最长英语单词链
    第十五周学习总结
    寻找“水王”
    Happy Necklace HDU
    Bi-shoe and Phi-shoe LightOJ
    The Embarrassed Cryptographer POJ
    Big Number HDU
    矩阵乘法模板C/C++
    Baby Step,Giant Step算法模板
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/13580627.html
Copyright © 2011-2022 走看看