当前位置: 首页>>代码示例>>C++>>正文


C++ SeqList类代码示例

本文整理汇总了C++中SeqList的典型用法代码示例。如果您正苦于以下问题:C++ SeqList类的具体用法?C++ SeqList怎么用?C++ SeqList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SeqList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char const* argv[])
{
  int length = 0;
  cout << "请输入人数:";
  cin >> length;

  vector<SeqList> c(length);  //建立向量c
  SeqList game;               //类的实例
  game.Joseph(c);             //调用成员函数求解
  return 0;
}
开发者ID:duyaokun,项目名称:Self-study-c-plus-plus,代码行数:11,代码来源:test5.cpp

示例2: assert

SeqList<ElemType>::SeqList(const SeqList<ElemType> &sa)
{
    int saLength = sa.GetLength();
    ElemType e;
    
    maxLength = sa.maxLength;
    elems = new ElemType[maxLength];
    assert(elems);
    length = 0;

    for (int i = 1; i <= saLength; i++) {
        sa.GetElem(i, e);
        InsertTailElem(e);
    }
}
开发者ID:suxinde2009,项目名称:Practical_Algorithms,代码行数:15,代码来源:SeqList.cpp

示例3: main

int main(int argc, char* argv[])
{
    cout << sizeof(SeqList<int>) << endl;
    SeqList<int> a;
    a.InsertAtRear(1);
    a.InsertAtRear(2);
    a.InsertAtRear(3);
    a.InsertAtRear(4);

    a.Delete(3);
    cout<<"顺序表长度为:"<<a.Length()<<endl;
    a.PrintList();
    return 0;
}
开发者ID:ncepuzhengyi,项目名称:DataStructure-VC,代码行数:14,代码来源:TestSeqList.cpp

示例4: main

int main(int argc, const char * argv[]) {

    char c='*';
    SeqList<int> *la = new SeqList<int>(6);
    int e = 0, i = 0;
    
    Status status;
    
    while (c != '0') {
        cout << endl << "1. 生成线性表.";
        cout << endl << "2. 显示线性表.";
        cout << endl << "3. 取指定元素.";
        cout << endl << "4. 设置元素值.";
        cout << endl << "5. 删除元素.";
        cout << endl << "6. 插入元素.";
        cout << endl << "7. 元素定位.";
        cout << endl << "8. 求线性表长度.";
        cout << endl << "0. 退出";
        cout << endl << "选择功能(0~8):";
        cin >> c;
        
        switch (c) {
            case '1':
            {
                la->Clear();
                status = SUCCESS;
                cout << endl << "输入e( e = 0时退出):";
                cin >> e;
                while (e != 0 && status != OVER_FLOW) {
                    status = la->InsertTailElem(e);
                    if (status == OVER_FLOW) {
                        cout << "线性表已满。" << endl;
                    }else {
                        cin >> e;
                    }
                }
            }
                break;
                
            case '2':
            {
                la->Traverse(Write<int>);
                //system("clear");
            }
                break;
                
            case '3':
            {
                cout << endl << "输入元素位置:";
                cin >> i;
                if (la->GetElem(i, e) == NOT_PRESENT) {
                    cout << "元素不存在" << endl;
                }else {
                    cout << "元素:" << e <<endl;
                }
                
            }
                break;
                
            case '4':
            {
               cout<< endl << "输入位置:";
                cin >> i;
                cout <<endl<<"输入元素值:";
                cin >> e;
                if (la->SetElem(i, e) == RANGE_ERROR) {
                    cout<<"位置范围错误"<<endl;
                }else {
                    cout<<"设置成功"<<endl;
                }
            }
                break;
                
            case '5':
            {
                cout << endl << "输入位置:";
                cin >> i;
                if (la->DeleteElem(i, e) == RANGE_ERROR) {
                    cout << "位置范围错." << endl;
                }else {
                    cout << "被删除元素值:" << e << endl;
                }
            }
                break;
                
            case '6':
            {
                cout << endl << "输入位置:";
                cin >> i;
                cout << endl << "输入元素值:";
                cin >> e;
                status = la->InsertElem(i, e);
                
                
                if (status == RANGE_ERROR) {
                    cout << "位置范围错." << endl;
                } else if (status == OVER_FLOW) {
                    cout << "线性表已满." << endl;
                }else {
                    cout << "插入成功." << endl;
//.........这里部分代码省略.........
开发者ID:suxinde2009,项目名称:Practical_Algorithms,代码行数:101,代码来源:main.cpp

示例5: check_viterbi

void
check_viterbi()
{
    ensure_hmm_built();
    ensure_hmm_test_seqs_created();

    cout << "******* check_viterbi(): " << test_seqs.size() << " artificial sequences" << endl;

    for (SeqList::const_iterator i = test_seqs.begin(); test_seqs.end() != i; ++i) {

        const size_t num_obs = i->end() - i->begin();

        //doesn't work well without logs on long sequences
        if (num_obs > 20)
        {
            continue;
        }

        index_list_t state_indices;
        ViterbiAlgorithm<false> viterbi_without_logs;
        viterbi_without_logs.viterbi(
            hmm,
            num_obs,
            i->begin(),
            i->end(),
            front_inserter(state_indices));

#ifdef VERBOSE_CHECKING
        cout
                << "Sequence " << (i - test_seqs.begin())
                << " has most likely state sequence (not using logs): ";
        for (index_list_t::const_iterator j = state_indices.begin(); state_indices.end() != j; ++j) {
            cout << *j;
        }
        cout << endl;
#endif

        index_list_t state_indices_using_logs;
        ViterbiAlgorithm<true> viterbi_with_logs;
        viterbi_with_logs.viterbi(
            hmm,
            num_obs,
            i->begin(),
            i->end(),
            front_inserter(state_indices_using_logs));

#ifdef VERBOSE_CHECKING
        cout
                << "Sequence " << (i - test_seqs.begin())
                << " has most likely state sequence (    using logs): ";
        for (index_list_t::const_iterator j = state_indices_using_logs.begin(); state_indices_using_logs.end() != j; ++j) {
            cout << *j;
        }
        cout << endl;
#endif

        BOOST_CHECK_EQUAL(state_indices, state_indices_using_logs);

#ifdef VERBOSE_CHECKING
        cout << endl;
#endif
    }
}
开发者ID:JohnReid,项目名称:biopsy,代码行数:63,代码来源:check_hidden_markov_model.cpp

示例6: showVertex

void graph::showVertex()//显示图的结点
{
	for(i=0;i<Vertices.ListSize();i++)//显示坐标
		cout<<setw(5)<<i;
	cout<<endl;
	for(i=0;i<Vertices.ListSize();i++)//显示数据
		cout<<setw(5)<<Vertices.Getdata(i);
	cout<<endl;
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:9,代码来源:图邻接矩阵+拓扑排序.cpp

示例7: getvalue

char graph::getvalue(const int i)//求取图的某个结点的值
{
	if(i<0||i>Vertices.ListSize())
	{
		cout<<"对不起参数越界出错!"<<endl;
		return false;
	}
	else
		return Vertices.Getdata(i);//采用顺序表的操作达成目标
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:10,代码来源:图邻接矩阵+拓扑排序.cpp

示例8: getweight

int graph::getweight(const int nodestart,const int nodeend)//求两个结点之间的边的权值
{
	if(nodestart<0||nodestart>Vertices.ListSize()||nodeend<0||nodeend>Vertices.ListSize())
	{
		cout<<"对不起参数越界出错!"<<endl;
		return false;
	}
	else
		return Edge[nodestart][nodeend];
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:10,代码来源:图邻接矩阵+拓扑排序.cpp

示例9: showgraph

void graph::showgraph()//图的显示函数
{
	for(i=0;i<Vertices.ListSize();i++)//用邻接矩阵来模拟图的边的相关信息
	{
		for(j=0;j<Vertices.ListSize();j++)
		{
			if(getweight(i,j)==maxweight)
				cout<<setw(5)<<"∞";//表示两个结点之间没有边
			else
				cout<<setw(5)<<getweight(i,j);
		}
		cout<<endl;
	}
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:14,代码来源:图邻接矩阵+拓扑排序.cpp

示例10: insertEdge

int graph::insertEdge(const int nodestart,const int nodeend,int weight)//添加一条边
{
	if(nodestart<0||nodestart>Vertices.ListSize()||nodeend<0||nodeend>Vertices.ListSize())
	{
		cout<<"对不起参数越界出错!"<<endl;
		return 0;
	}
	else
	{
		Edge[nodestart][nodeend]=weight;
		numofedges++;
		return 1;
	}
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:14,代码来源:图邻接矩阵+拓扑排序.cpp

示例11: deleteEdge

int graph::deleteEdge(const int nodestart,const int nodeend)//删除一条边
{
	if(nodestart<0||nodestart>Vertices.ListSize()||nodeend<0||nodeend>Vertices.ListSize())
	{
		cout<<"对不起参数越界出错!"<<endl;
		return 0;
	}
	else
	{
		Edge[nodestart][nodeend]=maxweight;
	    numofedges--;
		return 1;
	}
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:14,代码来源:图邻接矩阵+拓扑排序.cpp

示例12: register_hidden_markov_model_tests

void register_hidden_markov_model_tests(test_suite * test)
{
    ensure_hmm_built();
    ensure_hmm_test_seqs_created();

    test->add(BOOST_TEST_CASE(&check_forward_backward), 0);
    test->add(BOOST_PARAM_TEST_CASE(&check_baum_welch, test_seqs.begin(), test_seqs.end()), 0);
    test->add(BOOST_TEST_CASE(&check_hmm_overfitting), 0);
    test->add(BOOST_TEST_CASE(&check_long_test_seq), 0);
    test->add(BOOST_PARAM_TEST_CASE(&check_baum_welch_multiple, hmm_multiple_seqs.begin(), hmm_multiple_seqs.end()), 0);

    //it is not clear how effective these tests are
    //test->add(BOOST_PARAM_TEST_CASE(&check_more_states_improves_learning, test_seqs.begin(), test_seqs.end()), 0);
    //test->add(BOOST_TEST_CASE(&check_viterbi), 2); //can get 2 underflow problems on long sequences when not using logs
    //test->add(BOOST_TEST_CASE(&generate_test_sequences), 0);
}
开发者ID:JohnReid,项目名称:biopsy,代码行数:16,代码来源:check_hidden_markov_model.cpp

示例13: getfirstneighbor

int graph::getfirstneighbor(const int v)//求取其第一个相邻结边
{
	if(v<0||v>Vertices.ListSize())
	{
		cout<<"对不起参数越界出错!"<<endl;
		return false;
	}
	else
	{
		for(int col=0;col<=Vertices.ListSize();col++)
		{
			if(Edge[v][col]>0 && Edge[v][col]<maxsize)
				return col;//若存在相邻的结点返回其下标
		}
		return -1;//否则返回-1
	}
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:17,代码来源:图邻接矩阵+拓扑排序.cpp

示例14: getnextneighbor

int graph::getnextneighbor(const int nodestart,const int nodeend)//求取其下一条邻接边
{//找结点nodestart的<nodestart,nodeend>邻接边的下一条邻接边
	if(nodestart<0||nodestart>Vertices.ListSize()||nodeend<0||nodeend>Vertices.ListSize())
	{
		cout<<"对不起参数越界出错!"<<endl;
		return false;
	}
	else
	{//使col为nodeend+1因此寻找的边是nodestart的<nodestart,nodeend>邻接边的下一条邻接边
		for(int col=nodeend+1;col<=Vertices.ListSize();col++)
		{
			if(Edge[nodestart][col]>0&&Edge[nodestart][col]<maxsize)
				return col;
		}
		return -1;
	}
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:17,代码来源:图邻接矩阵+拓扑排序.cpp

示例15: deleteVertex

int graph::deleteVertex(const int v)//删除一个结点
{
	for(int i=0;i<Vertices.ListSize();i++)//删除结点必须把与这个结点相关联的全部的边首先删除
		for(int j=0;j<Vertices.ListSize();j++)
		{
			if(i==v||j==v && Edge[i][j]>0 && Edge[i][j]<maxweight)
			{
				Edge[i][j]=maxweight;
				numofedges--;
			}
		}
	int flag=Vertices.Delete(v);
	if(flag==1)//提供一个标志位为后面的调用方便
		return 1;
	else
		return 0;
}
开发者ID:heqinghqocsh,项目名称:BasicAlgorithm,代码行数:17,代码来源:图邻接矩阵+拓扑排序.cpp


注:本文中的SeqList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。