标题:求助-C数据结构
取消只看楼主
q495321651
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-6-17
结帖率:0
 问题点数:0 回复次数:0 
求助-C数据结构
/* Note:Your choice is C IDE */
#include "stdio.h"
#include<stdlib.h>
typedef struct node
{
    int date;
    struct node *next;
}node;

void sclist (node *h)
{
    node *p,*r,*q,*s;
    p=h->next;
    r=h->next;
    q=h->next;
    p=p->next;
    while(p!=NULL)
    {   
        while(p!=NULL)
        {
            
            if(q->date==p->date)
            {
                r->next=p->next;
                s=p;
                p=p->next;
                free(s);
                r=p;
                p=r->next;
            }
            else
            {
                r=r->next;
                p=p->next;
            }
        }
        q=q->next;
        r=q;
        p=r->next;
    }
}

void input(node *h)
{
    node *p,*r;
    int x;
    r=h;
    printf("请输入你的数据:");
    scanf("%d",&x);
    while(x!=-999)
    {
        p=(node *)malloc(sizeof(node));
        p->date=x;
        r->next=p;
        p->next=NULL;
        r=p;
        scanf("%d",&x);
    }
}

void putlist(node *h)
{
    node *p;
    p=h->next;
    while(p!=NULL)
    {
        printf("%d ",p->date);
        p=p->next;
    }
   
}
void main()
{
    node *h;
    h=(node *)malloc(sizeof(node));
    h->next=NULL;
    input(h);
    putlist(h);
    sclist(h);
    putlist(h);
}
想实现; 删除一组数中重复的数
 例如:
      输入:1 2 1 2 2 2 2 5
输出;       1 2 5
搜索更多相关主题的帖子: choice include 结构 next 
2012-10-01 21:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382419-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.616488 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved