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


C++ LinkList::Get方法代码示例

本文整理汇总了C++中LinkList::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkList::Get方法的具体用法?C++ LinkList::Get怎么用?C++ LinkList::Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinkList的用法示例。


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

示例1: main

int main()
{
   int a[] = {1,9,3,5,19,38,29,2,4,25,61,-1,7};
   LinkList<int>* list = new LinkList<int>(a, 13);
   list->PrintLinkList();
   int listlength = list->ListLength();
   std::cout<<"the list length is"<<listlength<<std::endl;
   int theLastElement = list->Get(13);
   assert(theLastElement == 7);
   std::cout<<"the last  element value   is"<< theLastElement << std::endl;
   std::cout<<"the values  that  the  array  contained currently display"<<std::endl;
   list->PrintLinkList();
   std::cout<<std::endl;
   std::cout<<"delete the  eigth element 2";
   std::cout<<std::endl;
   list->Delete(8);
   std::cout<<"the values  that  the  array  contained currently display"<<std::endl;
   std::cout<<"the  position of 61 is";
   std::cout<<std::endl;
   int position = list->Locate(61);
   std::cout<<std::endl;
   std::cout<<position<<std::endl;
   std::cout<<"the values  that  the  array  contained currently display"<<std::endl;
   list->PrintLinkList();
   std::cout<<std::endl;
    std::cout<<"now we add a value  at first  position"<<std::endl;
   list->Insert(1, 11111);
   std::cout<<"the values  that  the  array  contained currently display"<<std::endl;
   list->PrintLinkList();
   std::cout<<std::endl;
   list->Invert();
   std::cout<<"the  invert  array list is"<<std::endl;
   list->PrintLinkList();
}
开发者ID:zheniantoushipashi,项目名称:amazeAlgorithm,代码行数:34,代码来源:main.cpp

示例2: Display

void Display(LinkList<T> &list)
{
    cout << list.Count() << " element(s): ";
    for (int i = 1; i <= list.Count(); i++)
    {
        cout << list.Get(i) << " ";
    }
    cout << endl;
}
开发者ID:fanjeffrey,项目名称:axiom.master,代码行数:9,代码来源:test_linklist.cpp

示例3: main

int main()
{
    LinkList<int> ll;
    cout << "Created a link list..." << endl;
    cout << "length = " << ll.Count() << endl;

    for (int i = 1; i <= 10; i++)
    {
        int val = i * 2;
        ll.Insert(val, ll.Count() + 1);
        cout << val << " inserted. length = " << ll.Count() << endl;
    }
    Display(ll);

    cout << "Reversing ..." << endl;
    ll.Reverse();
    Display(ll);

    cout << "Reversing again ..." << endl;
    ll.Reverse();
    Display(ll);

    int idx = 1;
    int val = ll.Get(idx);
    cout << "Get(" << idx << ") = " << val << "." << endl;
    idx = ll.Locate(val);
    cout << "Locate(" << val << ") = " << idx << "." << endl;
    if (idx == ll.Locate(val))
    {
        cout << val << " is at " << idx << "." << endl;
    }

    idx = 7;
    val = ll.Get(idx);
    if (idx == ll.Locate(val))
    {
        cout << val << " is at " << idx << "." << endl;
    }

    idx = ll.Count();
    val = ll.Get(idx);
    if (idx == ll.Locate(val))
    {
        cout << val << " is at " << idx << "." << endl;
    }

    val = 9999999;
    if (-1 == ll.Locate(val))
    {
        cout << "Unable to locate " << val << "." << endl;
    }

    cout << "Inserting 3 at 3 ..." << endl;
    ll.Insert(3, 3);
    Display(ll);
    cout << "Deleting 3 ..." << endl;
    ll.Delete(3);
    Display(ll);

    cout << "Inserting 0 at 1 ..." << endl;
    ll.Insert(0, 1);
    Display(ll);
    cout << "Deleting 0 ..." << endl;
    ll.Delete(1);
    Display(ll);

    cout << "Inserting 11 at 12 ..." << endl;
    ll.Insert(11, 11);
    Display(ll);
    cout << "Deleting 11 ..." << endl;
    ll.Delete(11);
    Display(ll);
    try
    {
        cout << "call LinkList<int> lla = ll ..." << endl;
        LinkList<int> lla = ll;
        cout << "lla.length = " << lla.Count() << endl;

        cout << "call LinkList<int> llb(ll) ..." << endl;
        LinkList<int> llb(ll);
        cout << "llb.length = " << llb.Count() << endl;
        llb.Insert(77, 7);
        cout << "llb.length = " << llb.Count() << endl;

        cout << "call llb = lla ..." << endl;
        llb = lla;
        cout << "llb.length = " << llb.Count() << endl;
        cout << "lla.length = " << lla.Count() << endl;

        cout << "Splitting llb ..." << endl;
        llb.Insert(88, 8);
        cout << "llb.length = " << llb.Count() << endl;
        LinkList<int> llb2 = llb.Split();
        Display(llb);
        Display(llb2);

        cout << "Splitting ll ..." << endl;
        LinkList<int> llc = ll.Split();
        Display(ll);
        Display(llc);
//.........这里部分代码省略.........
开发者ID:fanjeffrey,项目名称:axiom.master,代码行数:101,代码来源:test_linklist.cpp

示例4: paint

//define 3 指针 a p q;
void paint(vector<Evertex> v)//边类,存储一条边的两个端点
{
    int i,j; //两个循环控制变量,在下面的向量循环和数组循环中将被多次调用。
    Node<AELvertex>* a[screenheight]; //扫描线数组指针 AELvertex 有线段顶点的y值,和另一端点的x值,还有斜率的倒数
    Node<AELvertex>* p; //p和q为扫描线类指针,是用来对指针链表进行插入和循环时用的
    Node<AELvertex>* q;
    
    int m;
    
    bool tag = true;//填充颜色变化的控制变量
    bool red_tag = true;
    bool green_tag = true;
    bool blue_tag = true;

    
    for(i = 0; i < screenheight; i++) //将扫描线数组指针制空 水平scan
        a[i] = NULL;
    int k = 0; //下面要进行的是将多边形的边信息转化为扫描线信息
    
    for(j = 0; j < v.size(); j++)//边的个数
    {
        p = new Node<AELvertex>; //new一个扫描线类空间,next为null
        p->next = NULL;
        if(v[j].y1 < v[j].y2) //两个if判断将线段两个端点中y坐标较大,将y值存入扫描线中,x坐标较小的,将x值存入扫描线中。
        {
            k = v[j].y1;//
            p->data.x = v[j].x1;
            p->data.y = v[j].y2;
            p->data.dx = (v[j].x1 * 1.0 - v[j].x2 * 1.0) / (v[j].y1 * 1.0 - v[j].y2 * 1.0);
        }
        if(v[j].y1 > v[j].y2)
        {
            k = v[j].y2;
            p->data.x = v[j].x2;
            p->data.y = v[j].y1;
            p->data.dx = (v[j].x1 * 1.0 - v[j].x2 * 1.0) / (v[j].y1 * 1.0 - v[j].y2 * 1.0);
        } //两个y值相等说明线段平行于x轴,直接忽略
        //将申请的空间连接到扫描线链表中
        if(a[k] == NULL) //若为空,则直接将数组元素指针指向新空间
            a[k] = p;
        
        else //不为空,则通过尾插法将新空间插入链表尾部,
        {
            q = a[k];
            while(q->next)
                q = q->next;
            q->next = p;
        }
    }
    //填充部分
    
    LinkList<AELvertex> AEL; //动态扫描线链表,动态扫描线类
    
    for(i = 0; i < screenheight; i++) //动态扫描链表的结点添加
    {
        
        if(a[i] != NULL) //当元素不为空,即在此处有扫描线结点时
        {
            
            p = AEL.first; //尾插法将a[i]中的结点信息插入AEL中
            while(p->next != NULL)
                p = p->next;
            p->next = a[i];
            a[i] =  NULL; //a[i]制空,防止野指针出现
            vector<AELvertex> sort; //一个动态扫描线类向量,用来对AEL链表进行排序用的
            p = AEL.first->next;
            while(p) //将AEL链表中的所有扫描线点的信息给sort
            {
                sort.push_back(p->data);
                p = p->next;
            }
            for(j = 0; j < sort.size(); j++) //对sort中的值排序,扫描线生成时需要所有点从小到大排好
            {
                for(k = 0; k < sort.size() - 1; k++)
                {
                    if(sort[k].x > sort[k+1].x)
                        Sort(sort[k], sort[k+1]); //值交换,开头声明的Sort函数就是在这里用的
                }
            }
            p = AEL.first->next;
            j = 0;
            while(p && j < sort.size()) //将排好序的结点在放回AEL链表中
            {
                Sort(p->data, sort[j]);
                j++;
                p = p->next;
            }
            sort.clear();
        }
        
        
        //扫描线生成,核心中的核心
        p = AEL.first->next;
        if(p) //判断AEL中是否有结点
        {
            for(j = 1; j <= AEL.Length(); j++)
            {
                k = AEL.Get(j).y; //取出每个结点的y的值,判断与当前扫描线的y坐标值即i比较,判断是否已经到线段顶部
                if(k <= i) //这里我用了一个小技巧,没有按课上讲的通过端点是否为极值点来判断端点应该去还是留
//.........这里部分代码省略.........
开发者ID:yyn835314557,项目名称:ComputerGraphics-homework,代码行数:101,代码来源:main.cpp


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