| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 389 人关注过本帖
标题:怎么改?
只看楼主 加入收藏
z1214977263
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-13
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
怎么改?
#include <iostream>

using namespace std;


struct Node
{
    double value;
    Node *next;
};
class collection
{
private:
    Node *head;
    Node *tail;
   
public:



    collection()
    {
        initial();
    }

    void initial()
    {
        head=new Node;
        head->next=NULL;
        tail=head;
    }

    void clear()
    {

        Node *index;
        do{
            index=head;
            head=head->next;
            delete index;
        }while(head != NULL);
        
        initial();
       // cout<<"5656656";
    }
   
    void input()
    {
        cout<<"输入(#结束):";
        char ch[10];
        cin>>ch;
        while( ch[0] != '#')
        {
            double a= atof(ch);
            this->addValue(a);
            cin>>ch;
        }
    }
   
    Node * search(Node *indexi)
    {
        Node *index=head->next;
        while(index != NULL)
        {
            if( index->value == indexi->value )
                break;
            index=index->next;
        }
        
        if(index !=NULL)
        {
            return index;
        }
        else return NULL;
        
    }
   
    int addValue(double newValue)
    {
    //    cout<<"55";
        Node *index=new Node;
        index->next=NULL;
        index->value=newValue;
        if( search(index) == NULL )
        {
            tail->next=index;
            tail=index;
            tail->next=NULL;
            return 1;
        }
        else return 0;
    }

    int addValue(Node *newNode)
    {

          if( search(newNode) == NULL )
        {
            Node *temp=new Node;
            temp->value=newNode->value;
                tail->next=temp;
                tail=temp;
                tail->next=NULL;
                return 1;
        }
        else return 0;
    }
   
    int DeleteValue(double newValue)
    {
        Node *temp=head;
        Node *temp1=head->next;
        while( temp1 !=NULL)
        {
            if(temp1->value == newValue)
                break;
            
            temp=temp1;
            temp1=temp1->next;
        }
        
        if(temp1 != NULL)
        {
            if(temp1->next==NULL)
            {
                tail=temp;
                tail->next=NULL;
               
                delete temp1;
               
            }
            else{
                temp->next=temp1->next;
                temp1->next=NULL;
                delete temp1;
            }
            return 1;
        }
        return 0;
    }

    void output()
    {
       cout<<"该集合:";
      Node *index=head->next;
      int count=0;
      while( index !=NULL)
      {
         
          cout<<index->value<<" ";
          index=index->next;
          count++;

      }
      cout<<endl;
      cout<<"该集合大小:"<<count<<endl;

    }
   
 /*   collection operator =(const collection & x1) const
    {
        collection temp;
        temp.head=x1.head;
        Node *index=x1.head->next;
        temp.tail=temp.head;
        while( index !=NULL)
        {
            temp
        }
    }*/

   
    void bin(collection *a1,collection *a2)
    {
        Node *index=head->next;
        while(index !=NULL)
        {
            
            a2->addValue(index);
            index=index->next;
        }

    //    a2->output();
        index=a1->head->next;
        while(index !=NULL)
        {

            a2->addValue(index);
            index=index->next;

        }
    }

    void jiao(collection *a1,collection *a2)
    {
        Node *index=head->next;
        while(index !=NULL)
        {
            if( a1->search(index) !=NULL )
               
            {
                Node *temp=new Node;
                temp->value=index->value;
                a2->addValue(index);
            }
            index=index->next;
        }
    }

    void cha(collection *a1,collection *a2)
    {
        Node *index=head->next;
        while(index !=NULL)
        {
            if(a1->search(index) ==NULL)
                a2->addValue(index);
            index=index->next;
        }
    }
};
搜索更多相关主题的帖子: private index 
2011-06-13 12:47
z1214977263
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-13
收藏
得分:0 
Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/1.exe : fatal error LNK1120: 1 unresolved externals
这个错误有可能是哪里的问题额?
2011-06-13 12:49
obeey
Rank: 2
等 级:论坛游民
帖 子:4
专家分:10
注 册:2011-6-13
收藏
得分:10 
你的main函数在哪里?
2011-06-13 13:19
z1214977263
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-13
收藏
得分:0 
链接不成,就是因为缺少主函数吗?
2011-06-13 14:26
Pirelo
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:118
专家分:550
注 册:2011-1-28
收藏
得分:10 
回复 4楼 z1214977263
程序代码:
#include <iostream>

using namespace std;


struct Node
{
    double value;
    Node *next;
};
class collection
{
private:
    Node *head;
    Node *tail;
   
public:



    collection()
    {
        initial();
    }

    void initial()
    {
        head=new Node;
        head->next=NULL;
        tail=head;
    }

    void clear()
    {

        Node *index;
        do{
            index=head;
            head=head->next;
            delete index;
        }while(head != NULL);
       
        initial();
       // cout<<"5656656";
    }
   
    void input()
    {
        cout<<"输入(#结束):";
        char ch[10];
        cin>>ch;
        while( ch[0] != '#')
        {
            double a= atof(ch);
            this->addValue(a);
            cin>>ch;
        }
    }
   
    Node * search(Node *indexi)
    {
        Node *index=head->next;
        while(index != NULL)
        {
            if( index->value == indexi->value )
                break;
            index=index->next;
        }
       
        if(index !=NULL)
        {
            return index;
        }
        else return NULL;
       
    }
   
    int addValue(double newValue)
    {
    //    cout<<"55";
        Node *index=new Node;
        index->next=NULL;
        index->value=newValue;
        if( search(index) == NULL )
        {
            tail->next=index;
            tail=index;
            tail->next=NULL;
            return 1;
        }
        else return 0;
    }

    int addValue(Node *newNode)
    {

          if( search(newNode) == NULL )
        {
            Node *temp=new Node;
            temp->value=newNode->value;
                tail->next=temp;
                tail=temp;
                tail->next=NULL;
                return 1;
        }
        else return 0;
    }
   
    int DeleteValue(double newValue)
    {
        Node *temp=head;
        Node *temp1=head->next;
        while( temp1 !=NULL)
        {
            if(temp1->value == newValue)
                break;
           
            temp=temp1;
            temp1=temp1->next;
        }
       
        if(temp1 != NULL)
        {
            if(temp1->next==NULL)
            {
                tail=temp;
                tail->next=NULL;
               
                delete temp1;
               
            }
            else{
                temp->next=temp1->next;
                temp1->next=NULL;
                delete temp1;
            }
            return 1;
        }
        return 0;
    }

    void output()
    {
       cout<<"该集合:";
      Node *index=head->next;
      int count=0;
      while( index !=NULL)
      {
         
          cout<<index->value<<" ";
          index=index->next;
          count++;

      }
      cout<<endl;
      cout<<"该集合大小:"<<count<<endl;

    }
   
/*   collection operator =(const collection & x1) const
    {
        collection temp;
        temp.head=x1.head;
        Node *index=x1.head->next;
        temp.tail=temp.head;
        while( index !=NULL)
        {
            temp
        }
    }*/

   
    void bin(collection *a1,collection *a2)
    {
        Node *index=head->next;
        while(index !=NULL)
        {
           
            a2->addValue(index);
            index=index->next;
        }

    //    a2->output();
        index=a1->head->next;
        while(index !=NULL)
        {

            a2->addValue(index);
            index=index->next;

        }
    }

    void jiao(collection *a1,collection *a2)
    {
        Node *index=head->next;
        while(index !=NULL)
        {
            if( a1->search(index) !=NULL )
               
            {
                Node *temp=new Node;
                temp->value=index->value;
                a2->addValue(index);
            }
            index=index->next;
        }
    }

    void cha(collection *a1,collection *a2)
    {
        Node *index=head->next;
        while(index !=NULL)
        {
            if(a1->search(index) ==NULL)
                a2->addValue(index);
            index=index->next;
        }
    }
}; 

void main()
{
    system("pause");
}
节点的插入,查询本身没问题,就看你要怎么用了,自己动手试试吧
2011-06-13 14:38
z1214977263
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-13
收藏
得分:0 
输入、输出集合
查询集合中的元素
在集合中进行插入、删除元素
怎么实现以上功能,还请高手指点。。初学者没怎么编过程序,还请各位加以帮助。。
2011-06-13 15:53
快速回复:怎么改?
数据加载中...
 
   



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

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