[英]Storing an array of sets of coordinates in C++ (vector of vector of pairs?)
[英]Storing values without an array or vector C++
我正在做一个项目,以使自己熟悉使用指针。 我想输入一组值,仅使用指针将它们合并并排序并打印出来。 我不想在这个项目中使用数组或向量...
我的问题:有没有办法跟踪用户输入的没有数组或向量的多个值?
未存储为数组的最常见数据结构是链表 。 链接列表使用指针将对象的“列表”“链接”在一起。
您可以使用链表的概念。
您可以将其编码如下
struct node
{
int n;
struct node *next;
}*start=NULL;
然后,要插入数字,请动态地将内存分配给节点变量,然后将其附加到起始节点,如下所示。
struct node *neww=(struct node *)malloc(sizeof(struct node));
neww->n=Number to insert;
neww->next=NULL;
start=neww;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.