• c链表


    #include <stdio.h>

    struct node
    {
    int val;
    node* next;
    };
    typedef node* list_node;
    list_node create(int n )
    {
    list_node head , temp ,pre;
    head = new node;
    pre = head;
    while ( n -- )
    {
    temp = new node;
    scanf("%d" , &temp->val);
    pre->next = temp;
    pre = temp;
    }
    pre->next = NULL;
    return head;
    }
    int add(list_node &head,int pos,int value)
    {
    list_node temp = head;
    int count = 0 ;
    while ( temp->next != NULL)
    {
    temp =temp->next;
    count ++;

    if (count == pos )
    break;
    }
    if (temp->next == NULL)
    return -1;
    else
    {
    list_node n = new node;
    n->val = value;
    n->next = temp->next ;
    temp->next = n ;
    return 1;
    }
    }
    int cont(const list_node head)
    {
    list_node temp = head;
    int count = 0 ;
    while ( temp ->next != NULL)
    {
    temp = temp->next;
    count ++;
    }
    return count;
    }
    node* reverse( list_node temp , list_node &head )
    {
    if ( temp == NULL || temp->next == NULL)
    {
    head->next = NULL;
    head = temp;
    return head;
    }
    list_node tmp = reverse( temp->next , head);
    tmp->next = temp;
    return temp;
    }

    int del(list_node &head , int pos)
    {
    int count = 0 ;
    list_node temp = head;
    while ( temp->next != NULL)
    {
    temp = temp->next ;
    count ++;
    if ( count == pos - 1 )
    break;
    }
    if ( temp->next == NULL )
    {
    return -1;
    }
    else
    {
    if ( temp->next->next == NULL)
    temp->next = NULL;
    else
    temp->next = temp->next->next;
    return 1;
    }
    }
    int main()
    {
    list_node head = create(5);

    del(head,3);

    reverse(head,head);
    return 0 ;
    }
  • 相关阅读:
    中国剩余定理
    Codeforces 240 F. TorCoder
    ZOJ 1202 Divide and Count
    洛谷 3380 【模板】二逼平衡树(树状数组套权值线段树)
    bzoj 3196/ Tyvj 1730 二逼平衡树 (线段树套平衡树)
    uva 10791
    uva 699 The Falling Leaves
    uva 839 Not so Mobile
    2017 济南综合班 Day 5
    2017 济南综合班 Day 4
  • 原文地址:https://www.cnblogs.com/lzhenf/p/2424449.html
Copyright © 2020-2023  润新知