问题标签 [circular-list]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2290 浏览

c++ - 在双循环链表的末尾插入节点

我正在编写一个程序来对双循环链表执行各种操作。所有其他功能都工作正常,但经过努力,我不知何故无法弄清楚为什么我的程序在执行 insert_end() 函数时会终止。功能是:

它是一个菜单驱动程序。

请帮助我有关 insert_end 功能..我是初学者...

0 投票
3 回答
2999 浏览

list - 在haskell中创建循环列表的三种方法

我对 Haskell 中的循环/无限列表感兴趣。我读到了let..in语句和where子句,我觉得它们可以发挥重要作用,但我仍然不明白。

具体来说,我已经为交替的 0 和 1 的无限列表编写了三个版本的代码。我认为这就是 Haskell 中循环列表的含义。

第二个对我来说似乎最简单、最短和最自然,但也许那是因为我仍然对 let..in 和 while 不太满意。

这三个列表是否都以相同的方式表示?

0 投票
4 回答
274 浏览

c - Reduce the number of iteration when traversing in linked list in C

I have a singly linked list which has 100 node. I need to check this linked list circular or not?

It can be achieved by traversing list and need to check last node link field equal to head.

This method will take maximum of 100 iteration. I want to reduce this to half, i mean by 50 iteration i need to achieve this.

Is it possible to do this? If yes, how we can do this?

0 投票
1 回答
6691 浏览

java - Circular Doubly LinkedList ListIterator

This is a homework question. I have a Double Linked Node class, Circular Double Linked List class which implements Iterable, and a Iterator class that implements Iterator. I understand the concept of an iterator where an implicit cursor sits between two nodes and on a call to next() it returns the node it just jumped over. I created a test class with a new list object. I then created an iterator and called next, I received the correct No Such Element exception but when I added some nodes to the list I received a Null Pointer Exception instead of it returning the last returned node. How can I correct this?

My Node class:

The List class with the private inner Iterator class:

0 投票
2 回答
209 浏览

scheme - Converting a list to a circular list in Chicken scheme?

In trying to find how to convert such a list, I came across Scheme streams and circular lists. However, that answer requires features in Racket not available in Chicken scheme. Can Anyone point Me in the direction of how to do this in Chicken scheme instead? Or in a scheme-variant-neutral fashion?

0 投票
1 回答
4366 浏览

java - 循环队列数组插入案例

我有实现这个非常接近完成的代码,导致我的 IndexOutofBounds 错误的原因似乎是在插入队列的一种情况下发生的。有任何想法吗?在我的课程开始时,我将后部和前部设置为 -1,计数为 0。数组的最大大小为 100。有一个 isfull 类可以测试计数是否为最大大小。

到目前为止,此代码按以下顺序将一个数字插入到数组中:0。检查它是否已满。如果是退出。1. 如果队列为空,则将其设为其中的第一项。2.如果队列不为空或不满,检查数组后面是否没有超过最大点数。如果没有,请将其添加到末尾。3.如果队列不是空的或满的,但是队列的后面是满的。循环并将其插入数组的开头。

问题是在以下情况下: - 数组填充有数字 1-100。此时阵列已满。- 移除前面,因此阵列从 2-100 变为第一个插槽为空。- 插入刚刚删除的号码,这会导致错误。此时 count+1 没有超过最大点数,因此它尝试将其添加到后面。但是由于最后一个位置已满,它不会循环,抛出一个数组越界异常。我可以添加什么来检查最后一个位置是否已填充并在这种情况下添加到数组的开头?

我的删除方法:

0 投票
2 回答
4639 浏览

c - C中的“循环”for循环

我有兴趣以这样一种方式迭代列表,即我可以从任何位置开始并通过一直到末尾来遍历整个列表,然后循环回到开头并迭代到起始位置。

假设我想为保证 4 个元素的数组执行此操作: char array[4] = {'a', 'b', 'c', 'd'}

我很难构建一个 for 循环,以便我可以从“a”开始,循环 abcd,或者从“b”开始,循环 bcda,或者从 d 开始,循环 dabc,等等。

我认为 for 循环的初始部分类似于 i = startingPosition。

我认为 for 循环的增量部分类似于 i = (i+1) % 4。这样,例如,从索引 2 开始,将上升到 3,然后是 0,然后是 1,等等。

中间的“终止”条件应该是什么?

谢谢!

0 投票
2 回答
3908 浏览

java - Java 循环链表

我必须创建一种方法来消除循环链表中的数字,比如我们的值最多为 9

并且我们希望不断地删除每第四个整数,它会如下所示

我必须创建一个移动来遍历元素,并创建一个消除来删除元素,但我可以自己做到这一点。我的 toString(); 有问题 方法,我目前没有返回任何值。

对我来说,我知道我将 position 指定为当前值,应该是1,因此虽然 position 不是null,但strVal应该是 position [1]+" "的间距。然后我将 position 称为下一个值[2],并且我继续直到null它之后9。因此strVal应该是1 2 3 4 5 6 7 8 9。但不幸的是,我没有返回任何东西,我尝试调试,并放置一些System.out.prinln();标记以查看我是否返回任何东西,但我没有。

0 投票
2 回答
1575 浏览

java - 尺寸 K 的循环链表

我有一个关于创建Circular Linked List没有添加方法的单曲的问题。只是 Node 的一个内部类,然后是一个带有toString方法的外部构造函数。
我很难returningList,我一直没有回报。我不知道为什么,因为我无法实现 add 方法。我必须在我的构造函数中创建一个循环链接列表,以便让我对它有一些了解。但是我如何将值分配给我Nodesheadtail

我认为原因在于 for loop
通过拥有current != null,它会继续运行,因为 current 永远不能为空,因为它无休止地引用,因为它是一个循环链接列表。但是,它至少会返回一些东西,而不是什么都没有。

说我打电话 Number newNum = new Number(6);
System.out.println(newNum);
我应该出局
1 2 3 4 5 6

0 投票
1 回答
215 浏览

android - 创建自定义视图组

我想在圆形设计中创建一个包含多个孩子的布局,并且从视点的中心我需要为每个孩子画线。

请在下面的图片中找到孩子们的看法是 4。在此处输入图像描述