相关疑难解决方法(0)

为什么我们使用数组而不是其他数据结构?

在我编程的时候,我还没有看到一个实例,其中数组比其他形式更适合存储信息.我确实认为编程语言中增加的"特性"已经改进了,并且取而代之.我现在看到他们没有被取代,而是被赋予了新的生命,可以这么说.

那么,基本上,使用数组有什么意义呢?

这不是为什么我们从计算机的角度使用数组,而是为什么我们从编程的角度使用数组(一个细微的差别).计算机对阵列的作用不是问题的关键.

arrays data-structures

192
推荐指数
3
解决办法
11万
查看次数

C++模板 - LinkedList

编辑 - 下面回答,错过了斜角的大括号.谢谢大家.

我一直试图写一个简单的单链表,我可以在其他程序中使用.我希望它能够使用内置和用户定义的类型,这意味着它必须是模板化的.

由于这个原因,我的节点也必须模板化,因为我不知道它将要存储的信息.我写了一个节点类如下 -

template <class T> class Node
{
    T data; //the object information
    Node* next; //pointer to the next node element

public:
    //Methods omitted for brevity
};
Run Code Online (Sandbox Code Playgroud)

我的链表类是在一个单独的类中实现的,并且在将新节点添加到列表末尾时需要实例化一个节点.我已经实现了如下 -

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

template <class T> class CustomLinkedList
{
    Node<T> *head, *tail;

public:

    CustomLinkedList()
    {
        head = NULL;
        tail = NULL;
    }

    ~CustomLinkedList()
    {

    }

    //Method adds info to the end of the list
    void add(T info)
    {
        if(head == NULL) //if our …
Run Code Online (Sandbox Code Playgroud)

c++ templates linked-list

11
推荐指数
2
解决办法
6万
查看次数

标签 统计

arrays ×1

c++ ×1

data-structures ×1

linked-list ×1

templates ×1