zoukankan      html  css  js  c++  java
  • c

    #include<stdio.h>
    #include<stdlib.h>
    struct node
    {
    int data;
    struct node *next;
    };
    int main()
    {
    int n;
    while (scanf("%d",&n)!=EOF)
    {
    int m;
    int i,t=0;
    struct node *head,*p,*q,*d,*tail;
    head=new node;
    head->next=NULL;
    tail=head; //tail表示链表的尾部
    for(i=0; i<n; i++)
    {
    q=new node;
    scanf("%d",&q->data); //输入链表元素值
    q->next=NULL; //
    tail->next=q; //tail的下一个元素是当前输入的元素
    tail=q; //现在尾部变成了当前的元素
    }
    scanf("%d",&m);
    printf("%d ",n);
    q=head->next;
    while(q!=NULL) //依次遍历输出链表里每个元素的值
    {
    printf("%d",q->data);
    if(q->next!=NULL)
    printf(" ");
    q=q->next;
    }
    printf(" ");
    d=head;
    while(d != NULL && d->next!=NULL) //d和d的下一个元素不能为空,想一想为什么下一个也不能为空
    {
    if (d->next->data == m){ //d的下一个元素如果等于m
    d->next = d->next->next; //删除d的下一个元素的值
    t++; //记录被删除元素的个数
    }else
    d = d->next;
    }
    printf("%d ",n-t); //全个数减去被删除的个数
    p=head->next;
    while(p!=NULL) //依次输出链表里每个元素的值
    {
    printf("%d",p->data);
    if(p->next!=NULL)
    printf(" ");
    p=p->next;
    }
    printf(" ");
    }
    return 0;
    }
    /*
    10
    56 25 12 33 66 54 7 12 33 12
    7
    56 25 33 66 54 7 33
    */

    https://git.postgresql.org/gitweb/?p=postgresql.git;a=blobdiff;f=src/backend/replication/logical/snapbuild.c;h=196c1880337b08d80f337844f659364bd41cfe30;hp=f00fd7d422e43d058f64185ec77c2cfbd3b6fa52;hb=fe7337f2dc3177da19b647fcda3a33b73da82e14;hpb=5f93c37805e7485488480916b4585e098d3cc883

    https://git.postgresql.org/gitweb/?p=postgresql.git;a=summary

  • 相关阅读:
    LeetCode "Median of Two Sorted Arrays"
    LeetCode "Distinct Subsequences"
    LeetCode "Permutation Sequence"

    LeetCode "Linked List Cycle II"
    LeetCode "Best Time to Buy and Sell Stock III"
    LeetCode "4Sum"
    LeetCode "3Sum closest"
    LeetCode "3Sum"
    LeetCode "Container With Most Water"
  • 原文地址:https://www.cnblogs.com/icodefive/p/9875406.html
Copyright © 2011-2022 走看看