zoukankan      html  css  js  c++  java
  • 数据结构学习连载2(实现上篇中的提高要求)

    1.在SeqList.h中添加声明: void DeleteItemAll(const int item);   //删除所有等于item的记录

    2.在SeqList.cpp中实现该函数如下:

    /*
    * 函数名称: DeleteItemAll
    * 输 入:item
    * item: 需要删除数据 
    * 输 出:
    * 功能描述: 删除所有等于item的记录
    * 作 者: 吴友强
    * 日 期: 2009年10月12日
    * 修 改:
    * 日 期:
    */
    void SeqList::DeleteItemAll(const int item)
    {
     if (0 == size)
     {
      cerr << "顺序表已空无元素可删!" << endl;
      exit(1);
     }

     for (int i=size-1; i>=0; i--)
     {
      if (data[i] == item)
      {
       Delete(i);
      }
      else
      {
       continue;
      }
     }

    3.SeqListTest.cpp测试程序:

    /*
    * Copyright (c) 2009,FreshAir团队嵌入式软件研发组
    * All rights reserved.
    *
    * 文件名称:SeqListTest.cpp
    * 摘 要: 测试顺序表的功能
    *
    * 当前版本:1.0
    * 作 者: 吴友强
    * 完成日期:2009年10月12日
    *
    * 取代版本:
    * 原作者 :
    * 完成日期:
    */

    #include "SeqList.h"

    int main(int argc, char *argv[])
    {
     SeqList seqlist;
     int i;

     for (i=0; i<10; i++)
     {
      seqlist.Insert(i+10, i);
     }

     cout << "测试GetData()成员函数结果如下:" << endl;
     for(i=0; i<10; i++)
     {
      cout << seqlist.GetData(i) << " ";
     }
     
     cout<< endl << "测试Delete()成员函数结果如下" << endl;
     for(i=0; i<10; i++)
     {
      cout<<seqlist.Delete(0)<<" "<<endl;
     }
     
     seqlist.Insert(10, 0);
     seqlist.Insert(6, 0);
     seqlist.Insert(10, 0);
     seqlist.Insert(8, 0);
     seqlist.Insert(10, 0);

     for (i=0; i<5; i++)
     {
      cout << seqlist.GetData(i) << " ";
     }
     cout << endl << "测试DeleteItemAll()成员函数结果如下:" << endl;
     seqlist.DeleteItemAll(10);

     for (i=0; i<2; i++)
     {
      cout << seqlist.GetData(i) << " ";
     }
     return 0;
    }
    }

  • 相关阅读:
    nginx centos 服务开机启动设置实例详解
    CentOS打开关闭永久防火墙指定端口
    使用 nginx 反向代理 sqlserver 访问 配置
    Springboot集成Mybatis
    linux中查看java进程
    mybatis关于jdbc连接报错,5.5.62MySQL连接,出现com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure等问题解决方法
    索引的分析
    MySQL慢查询分析工具
    MySQL锁
    nGrinder介绍、编写脚本与执行(完整版)
  • 原文地址:https://www.cnblogs.com/brucewoo/p/2252051.html
Copyright © 2011-2022 走看看