| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 434 人关注过本帖
标题:C++中,delete函数怎么使用
只看楼主 加入收藏
jjddxs
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-12-3
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
C++中,delete函数怎么使用
麻烦帮忙看看这代码  
    #define NULL 0
#include<stdlib.h>
#include<stdio.h>
typedef struct node{
    char a;
    struct node *link;
}node,*nodelink;
void readlink(nodelink head){
    nodelink p,q;
    char c;
    p=head;
    printf("Input a linktable(a string):");
    scanf("%c",&c);
    if(c=='\n')
        printf("This string is empty.");
    while(c!='\n')
    {    q=(nodelink)malloc(sizeof(node));
        q->a=c;
        p->link=q;
        p=q;
        scanf("%c",&c);
    }
    p->link=NULL;
}
void writelink(nodelink head)
{
    nodelink q;
    if(head->link==NULL)
        printf("This link is empty.\n");
    for(q=head->link;q;q=q->link)
        printf("%c",q->a);
    printf("\n");
}
int insert(nodelink head,char k1,char k2)
{
    nodelink p,q;
    p=head->link;
    while(p->a!=k1&&p)
        p=p->link;
    if(p)
    {    q=(nodelink)malloc(sizeof(node));
        q->a=k2;
        q->link=p->link;
        p->link=q;
        return 1;
    }
    else
    {    printf("There is no %c\n",k1);
        return 0;
    }
    int delete(nodelink head,char k)
    {    nodelink p,q;
        q=head;
        p=head->link;
        while(((p->a)!=k&&p){
            q=q->link;
            p=p->link;
        }
        if(p)
        {    q->link=p->link;
            return 1;
        }
        else
        {    printf("There is no %c\n",k);
            return 0;
        }
    }
    void opside(nodelink head)
    {    nodelink p,q;
        p=head->link;
        while(p->link){
            q=p->link;
            p->link=q->link;
            q->link=head->link;
            head->link=q;
        }
        main()
        {    char k1,k2,k3;
            nodelink head;
            head=(nodelinlk)malloc(sizeof(node));
            head->link=NULL;
            readlink(head);
            if(head->link!=NULL)
            {    printf("Build link is :");
                writelink(head);
            }
            if(head->link!=NULL)
            {    printf("Please input a char you want to insert after:");
                k1=getch();
                printf("%c\n",k1);
                printf("Please input a char you want to insert:");
                k2=getch();
                printf("%c\n",k2);
                if(insert(head,k1,k2))
                {    printf("After %c insert %c,link is:",k1,k2);
                    writelink(head);
                }
                printf("Please input a char you want to delete:");
                k3=getch();
                printf("%c\n",k3);
                if(delete(head,k3))
                {    printf("after delete %c,link is:",k3);
                    writelink(head);
                }
                if(head->link!=NULL)
                {    printf("Opsite result is:");
                    opside(head);
                    writelink(head);
                    free(head);
                }
            }
        }
搜索更多相关主题的帖子: include 
2013-12-03 12:40
yuccn
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:何方
等 级:版主
威 望:167
帖 子:6815
专家分:42393
注 册:2010-12-16
收藏
得分:14 
乱哄哄的没法看

我行我乐
公众号:逻辑客栈
我的博客:
https://blog.yuccn. net
2013-12-03 17:25
快速回复:C++中,delete函数怎么使用
数据加载中...
 
   



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

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