| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 655 人关注过本帖
标题:C++中,delete函数怎么使用
只看楼主 加入收藏
jjddxs
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-12-3
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:7 
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
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
看了,然后呢?

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-12-03 14:39
xyt2012
Rank: 2
等 级:论坛游民
帖 子:11
专家分:47
注 册:2013-11-1
收藏
得分:0 
555566666
2013-12-03 16:38
jjddxs
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-12-3
收藏
得分:0 
回复 2楼 peach5460
就是我在VC6中运行,通不过去,报错是这样的ignored on left of 'int' when no variable is declared,一直调不好,求帮助啊,谢谢了
2013-12-04 12:11
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
代码太乱了

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2013-12-04 13:13
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:20 
错误太多   

我也就是保证你能被编译通过了  运行能否通过  你自己再调试吧   

不会调试  是不行滴

程序代码:
#define NULL 0
#include<stdlib.h>
#include<stdio.h>
#include<conio.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;
    }
}
int main()
{
    char k1,k2,k3;
    nodelink head;
    head=(nodelink)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);
        }
    }
}



DO IT YOURSELF !
2013-12-04 13:25
jjddxs
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-12-3
收藏
得分:0 
回复 6楼 wp231957
谢谢了
2013-12-05 16:21
jjddxs
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2013-12-3
收藏
得分:0 
回复 6楼 wp231957
谢谢了
2013-12-05 16:21
快速回复:C++中,delete函数怎么使用
数据加载中...
 
   



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

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