我想要一个这个鳕鱼的测试用例,有没有人帮助我? [英] i want a test case for this cod , is there any one help me?

查看:71
本文介绍了我想要一个这个鳕鱼的测试用例,有没有人帮助我?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include "stdafx.h"
#include<iostream>
using namespace std ;

struct node
{
    int data ;
    int h;
    node *leftchild;
    node *current;
    node *rightchild;
};






int h(struct node* x)
{
    if (x == NULL)
        return 0;
    return x->h;
}




int balanceavl(struct node *n)
{
    if (n == NULL)
        return 0;
    return (h(n->leftchild) , h(n->rightchild));


}





node* ll(struct node *b)
{
    struct node *a = b->leftchild;
    struct node *c = a->rightchild;

    a->rightchild = b;
    b->leftchild = c;

    b->h = max(h(b->leftchild), h(b->rightchild))+1;
    a->h = max(h(a->leftchild), h(a->rightchild))+1;

    return a;
}


node* rr(struct node*a)
{
 struct node *b = a->rightchild;
 struct node *c = b->leftchild;
 a->rightchild = c->leftchild;
 b->leftchild = c->rightchild;
 c->rightchild = b;
 c->leftchild = a;
 a->h = max ( h(a->leftchild) , h(a->rightchild) ) + 1 ;
 b->h = max ( h(b->leftchild) , h(b->rightchild) ) + 1 ;
 c->h= max ( h(a) , h(b) ) + 1 ;
 return c;
}






node* insert( struct node *current,int data)
{

 if( current==NULL )
 {
    node* x = new node ;
    x->data = data;
    x->leftchild = NULL;
    x->rightchild = NULL;
    x->h = 1;
    return(x);
 }
 else if( data < current->data )
 {
  current->leftchild = insert(current->leftchild,data );
 }
 else
     current->rightchild =insert (current->rightchild,data);
 current->h =max(h(current ->leftchild), h(current->rightchild)) + 1;






 int b = balanceavl(current);


    //ll
 if (b > 1 && data < current->leftchild->data)
        return ll(current);

 //rr
 if (b < -1 && data > current->rightchild->data)
     return rr(current);

    //lr
 if (b > 1 && data> current->leftchild->data)
    {
        current->leftchild =  rr(current->leftchild);
        return ll(current);
    }

    //rl
 if (b < -1 && data < current->rightchild->data)
    {
        current->rightchild = ll(current->rightchild);
        return rr(current);
    }

 return current;





}
///////////////////////////////////////////////////////
void preorder(struct node *current)
{
    if(current != NULL)
    {
        cout<<current->data;
        preorder(current->leftchild);

        preorder(current->rightchild);
    }
}
//////////////////////////////////////




void inorder(struct node *current)
{
    if(current !=NULL)
    {
        inorder(current->leftchild);
        cout<<current->data;
        inorder(current->rightchild);
    }


}


 node* Remove(struct node *current , int data)
{
    if (current== NULL)
        return current ;

    if (data< current->data)
        current->leftchild = Remove(current->leftchild, data);

    else if(data > current->data )
        current->rightchild = Remove(current->rightchild, data);

    else
    {

        if( (current->leftchild == NULL) || (current->rightchild == NULL) )
        {
            struct node *temp = current->leftchild ? current->leftchild :current->rightchild;

            if(temp == NULL)
            {
                temp = current;
               current = NULL;
            }
            else
            {
                *current = *temp;

            }

            free(temp);
        }
        else
        {
            struct node* root = current->rightchild;
            while (root->leftchild != NULL)
                root = root->leftchild;
            struct node* temp = root;
           current->data= root->data;
           current->rightchild = Remove(current->rightchild, root->data);
        }
    }
    if (current == NULL)
        return current;

    current->h = max(h(current->leftchild), h(current->rightchild)) + 1;
    int b = balanceavl(current);

    //ll
    if (b > 1 && balanceavl(current->leftchild) >= 0)
        return ll(current);


    //lr
    if (b > 1 && balanceavl(current->leftchild) < 0)
    {
        current->leftchild =  rr(current->leftchild);
        return ll(current);
    }


    //rr
    if (b < -1 && balanceavl(current->rightchild) <= 0)
        return rr(current);


   //rl
    if (b < -1 && balanceavl(current->rightchild) > 0)
    {
        current->rightchild = ll(current->rightchild);
        return rr(current);
    }

    return current;
}








int main()
{
    struct node *current= NULL;

    int k,m;

    do{


        cout<<"if u want add item in avl tree plz enter 1\nif u want remove item from avl tree plz enter 2\nif u want show item plz enter 3\nif u want exit enter 0\n";


        cin >>k;

        switch(k)
        {
        case 1:
        {
            cout<<"enter your item:";
            cin>>m;
            current =insert(current, m);
            cout<<endl;
            break;

        }
        case 2:
        {
            cout<<"enter your item:";
            cin>>m;
            Remove(current,m);
            inorder(current);
            cout<<endl;
            break;
        }
        case 3:
        {
            cout<<"preorder: ";
            preorder(current);
            cout<<"\t"<<"inorder: ";
            inorder(current);
            cout<<endl;
            break;

        }
        default:
        cout<<" no item :( ";
        }



    }while(k!= 0);

    return 0;
}

推荐答案

最好的Cod的测试案例总是要在一个好的面糊中煎炸它,并根据你的优势使用薯片和豌豆软化。盐和醋是可选的,但只会改善最坏的艺术例子。
$ b因此,Cod是格里姆斯比存在的唯一理由,否则将被视为对文明的犯罪。你可以通过去那里测试,他们会为这项业务感到高兴。: - {}
The best test case for Cod is always to deep fry it in a good batter and serve with chips and peas softened according to your lattitude. Salt and vinegar are optional but will only fail to improve the worst examples of the art.
Cod is therefore the only justification for the existence of Grimsby which would otherwise be considered a crime against civilisation. You can test this by going there, they'd be glad of the business. :-{}


轮到你来测试你的代码了。为什么你不写这么多ch代码没有任何使用它的想法。



我个人的观点是你在乞求别人做你的工作时做的很糟糕。



你是不是害怕恶业?
It is your turn to test your code. Why arent you write so much code wihtout any ideas of using it.

My personal opinion is that you are doing bad things in begging other people to do your work.

Arent you afraid of bad karma?


这篇关于我想要一个这个鳕鱼的测试用例,有没有人帮助我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆