| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1628 人关注过本帖
标题:大家帮我看看 26个字母删除的操作,怎么只能删除一个呀``???
只看楼主 加入收藏
神vLinux飘飘
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:浙江杭州
等 级:贵宾
威 望:91
帖 子:6140
专家分:217
注 册:2004-7-17
收藏
得分:0 
/*
这个是我用双链表写的.
链表结构采用了<HEAD> - <unit1> - <unit2> - ... - <unitn> - <END> 的结构

神vlinux飘飘
*/

#include <stdio.h>

/*基本单元character*/
struct character
{
    char c;
    struct character *front;
    struct character *next;
};

struct character *head;    /*链表表头*/
struct character *end;    /*链表表尾*/
struct character *point;    /*操作指针*/

void init();    /*链表初始化函数*/
void show();    /*链表全体单元输出函数*/
void del(struct character*); /*链表删除单元函数*/
/*按照字符查找链表单元函数.如果该字符存在返回该字符单元的地址,如果不存在则返回NULL*/
struct character *search(char ch);   

int main(void)
{
struct character *temp;
char cmd,x;

    init();/*初始化*/
   
    /*程序开始*/
    do{
        show();
        printf("\ninput deleted letter:");
        scanf("%c%c",&cmd,&x);
        if( cmd=='0' )
            break;
        if( (temp=search(cmd))==NULL)
            printf("\nError, the letter didn't exist!\n");
        else
            del(temp);
    }while(1);
}

void init()
{
struct character *temp;
int i;

    /*初始化链表表头和表尾*/
    head = (struct character*)malloc(sizeof(struct character));
    end  = (struct character*)malloc(sizeof(struct character));
    head->front = NULL;
    end->next = NULL;
    head->next = end;
    end->front = head;

    /*初始化链表26个单元,分配相应字母给各个单元*/
    point = head;
    for(i=0;i<26;i++)
    {
        temp = (struct character*)malloc(sizeof(struct character));
        temp->c = 'z'-i;
        temp->front = point;
        temp->next = point->next;
        point->next->front = temp;
        point->next = temp;
    }
}

void show()
{
    /*遍历输出所有单元,除了头单元(表头)和尾单元(表尾)*/
    point = head;
    while(point->next != NULL)
    {
        printf("%c ",point->c);
        point = point->next;
    }
}

struct character *search(char ch)
{
    /*遍历查询该字符所对应的单元*/
    point = head;
    while(point->next != NULL)
        if(point->c == ch)
            return point;
        else
            point = point->next;
    return NULL;
}

void del(struct character *temp)
{
    /*删除链表*/
    temp->front->next = temp->next;
    temp->next->front = temp->front;
    free(temp);
}

淘宝杜琨
2005-04-10 00:02
guitarliukai
Rank: 1
等 级:新手上路
帖 子:73
专家分:0
注 册:2004-12-5
收藏
得分:0 

#include <stdio.h> #define len sizeof(struct a) #include <malloc.h>

struct a {char lk; struct a *next ; };

main() {struct a *head,*p,*q,*s; int i; char ch; head=p=(struct a *) malloc(len); for(i=1;i<=26;i++) { (p->lk)=('a'+i-1); p->next=(struct a *)malloc(len); p=p->next;

} p->next=NULL;

p=head; while (p->next != NULL)

{ printf("%c ",p->lk); p=p->next; } /* printf("\n"); */

q=p=head; printf("\ninput deleted letter:"); scanf("%c",&ch); while(ch != '0') { q=p=head;

while(p->lk != ch && p->next != NULL) {q=p; p=p->next;} if(p==head) { head=head->next;free(p); } else { if(p->lk == ch)

{ q->next=p->next; free(p) ; } else printf("can't find it"); }

q=p=head; printf("\n"); while (p->next != NULL)

{ printf("%c ",p->lk); p=p->next; } /* printf("\n"); */

q=p=head;

printf("\n2:input deleted letter"); fflush(stdin); scanf("%c",&ch); }

p=head; while(p->next != NULL) {printf("%c",p->lk); p=p->next;}

q=p=head; 给修改一下我这蓝字的程序`````````插入的条件错没````??? printf("\ninput insert letter"); /*insert */ fflush(stdin); scanf("%c",&ch);

while(ch != '0') { q=p=head; while(p->lk < ch && p->next != NULL) { q=p; p=p->next;}

if(p==head) { s=(struct a *) malloc(len); s->lk=ch; s->next=head; p=s; }

else { if (p->lk == ch) { printf("inserted is exist"); } else {s=(struct a *) malloc(len); s->lk=ch; s->next=p; q->next=s; p=head;}

} printf("\ntest %c\n",p->next->lk);

while(p->next != NULL) {printf("%c",p->lk); p=p->next;} p=head; printf("\n2insert a letter");

fflush(stdin); scanf("%c",&ch);

}

}


我录的歌 http://1680279./ 我现在打不开了????
2005-04-10 10:29
快速回复:大家帮我看看 26个字母删除的操作,怎么只能删除一个呀``???
数据加载中...
 
   



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

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