Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [iterator]

An iterator is an object-oriented programming pattern which for the most part functions similarly to a pointer to an object inside a collection with the added ability to traverse through the collection in a defined manner, agnostic of the actual implementation or even object addresses in physical memory. Iterators may be further limited in particular traversal directions.

Filter by
Sorted by
Tagged with
10
votes
2answers
637 views

Iterator for traversing a tree [v2]

this is an update of the implementation after I followed the feedback from Iterator for traversing a tree. After that I did changed quite a bit on the design and decided to ask for another round of ...
3
votes
1answer
61 views

Iterator for traversing a tree

What I want to achieve is the following: ...
4
votes
1answer
52 views

Paginate IEnumerable<T> sequence

I used the following to split sequence into batches: ...
0
votes
1answer
17 views

Bidirectional numeric (floating point) sequence iterator

I wanted a neat iterator that will always give me neat sequence of step spaced numbers. This is what I came up with, but I am a bit skeptical that I covered all ...
2
votes
0answers
42 views

Combining two nested for loops into one [closed]

Description What this does is it takes a randomly generated 64x64 stack and checks for overlap within the 64x64 array. Here is an example: https://imgur.com/a/kkPRzhn. Each color is its own ...
2
votes
1answer
54 views

A simple priority queue in Java via linked list sorted by priority keys

Now I have this very simple priority queue. add and changePriority both run in \$\mathcal{O}(n)\$ and ...
1
vote
1answer
60 views

A GapHelper static class to create unique (non-existing) size restricted names

I am working with a 3th party library which has following interface defined for a processing task: ...
7
votes
1answer
208 views

Map unique raw words to a list of code words

Problem Write a function that replaces the words in raw with the words in code_words such that the first occurrence of each ...
3
votes
1answer
66 views

Aggregation on list forEach and maps improvals

I am using a function in a SpringBoot @RestController, with Lombok This function is an intermediate result that permit me to do an aggregation between two classes. This 2 classes are: ...
1
vote
1answer
79 views

c++ python like range function to use in for loops

It's a simple range function that works like python range and it is only a syntactic sugar for the usual for loop if we want to operate on numbers in the range from 1 to 10 (1 ... 9) we use this code ...
7
votes
3answers
333 views

LINQ Extension methods MinBy and MaxBy

LINQ Extension I present a LINQ method ArgBy that returns the item of a sequence that corresponds to the predicate specified. Two additional methods ...
8
votes
2answers
155 views

Doubly-linked-list implementation in C++

I am fairly new to C++ and have been trying to make a doubly-linked-list class that imitates std::list (though not all of it). I'd appreciate if someone can look at my code and let me know if I have ...
3
votes
2answers
63 views

A basic trivia app

The app grabs 10 questions from an API, displays them one by one with 4 multiple choice answers. These answers are clickable buttons that alert to whether the answer is correct or not. Finally the ...
7
votes
2answers
135 views

Python-style Generator in Java

I have implemented Python-style generators within Java. I might be reinventing the wheel here, but I feel that the ability to define a Generator with an anonymous class is the most flexible approach. ...
2
votes
1answer
44 views

C++ singly linked list with iterator

I have written a simple singly linked list in C++. I have previously had a data structure in an interview criticised for being too C-like (no iterators and using new/delete) instead of smart pointers. ...
2
votes
1answer
76 views

Add method to Ruby's Enumerable module that produces every nth element

The task is to enhance the Enumerable module with a method nth(). The method shall create a new list, which contains every nth-...
6
votes
0answers
102 views

General algorithm to calculate sums of all subsets of a given sequence of numbers

Background A recent question Print sums of all subsets made its way to the Hot Network Questions list. The problem is simple: Print sums of all subsets of a given set Given an array of ...
5
votes
2answers
77 views

Filename sequencer with outdated C++

My path to learning C++ has been a rough one. Currently, I'm writing a project and my knowledge is very outdated. While I can write code that accomplishes the tasks required, I'd like to improve and ...
2
votes
2answers
52 views

Implementation of enumerate

I'm trying to implement the enumerate built-in using iterators. So far it works but for unordered objects, such as sets or dictionaries, I'm not sure if this implementation is considered valid, ...
5
votes
3answers
241 views

SkipLast of an IEnumerable<T> - Linq Extension

As my answer to this question, I came up with this solution: ...
4
votes
1answer
49 views

Using best practice with complex iteration

I'm new to Rust so I'm still learning how to use best practice in complex examples. Below is some code I've used in one of my programs, a simple implementation of a standard neural network. Here is ...
4
votes
1answer
114 views

Email Generator

I've made a email generator, that uses a HTML template and replaces keywords in the template with information taken from a database. I'm looking to see if there is a way to improve the coding. ...
3
votes
1answer
58 views

C function to fully consume a Python iterator

I was reading into the proper way to consume an iterator on this question as well as here and I notices there is no actual proper function for this that clearly explains itself. Using: ...
2
votes
1answer
42 views

Rendering JSON arrays of unequal length as a table

I have a website where my users can create "table-like" layout dynamically. So imagine that my users can upload a text document, and then append columns to the document, and the output will then be ...
4
votes
1answer
79 views

Iterable hashtable implementation in C

I'm just finished my version of iterable hashtable. I want to review code in general (code style, data structures, remarks about the algorithms) and I have some questions: I don't know how to ...
1
vote
1answer
58 views

Replace values in R data frame according to values in other data frame

I would like to change row names values from a first data frame if these rows names are present in another data frame, and change it to a corresponding value (defined in the second data frame). I ...
3
votes
1answer
86 views

Most efficient way to loop through files using VBA Excel

I have a procedure for looping through all files in folders and subfolders starting at a folder which the user can select. The user can select both the source and target folder. I'm using Excel VBA ...
3
votes
0answers
35 views

Rust Iterator that correlates a slice with itself

In my effort to learn Rust I've tried implementing an Iterator that splits up a buffer in two halves, and correlates both halves by sliding them over each other with different positions (lags). You ...
2
votes
2answers
70 views

Iterating over a range of integer ranges in Java

My use case is this: RangeDemo.java: ...
1
vote
1answer
67 views

Sequence for Pre-order traversal of Binary Trees

I wanted to make a Sequence that can do a pre-order traversal of Binary Tree. Doing so provides automatically unlocks wonderfully useful methods, like ...
5
votes
2answers
77 views

Simple linked list with two iterators

As part of the practice, I created minimalist linked list named SimpleList which can be iterated in two different ways: one element after another or by every second ...
21
votes
4answers
4k views

Count all vowels in string

For a homework assignemnt, I was asked to complete this CodeStepByStep problem. It's coded correctly and gave me a right answer. I'm just wondering if there's an easier way to solve this problem ...
1
vote
2answers
46 views

Combining arbitrary number of lists inside json

I have some JSON where each key stores an array, and I need to combine all those arrays into a single array. My current solution doesn't seem the most friendly to review, but without ...
2
votes
1answer
146 views

Speed up fast poisson disk sampling generator in Python

I wrote a generator class which implements Fast Poisson Disk Sampling algorithm in Python. I did some optimizations like, x ** 2 -> x * x, using unpacking ...
4
votes
3answers
110 views

Linked list implementation C++

I hope this is the right way of doing things: I've previously posted a request for a code review and gotten feedback. Now I have new improved code that I would like a code review on again. Old: C++ ...
5
votes
2answers
117 views

C++ linked list iterator implementation

I'm a first year computer engineering student and would appreciate feedback on some code. I've created a linked-list with an iterator to be able to range for loops like: ...
6
votes
0answers
71 views

Generating integer partitions

I've tried to implement integer partition algorithm as described in blogpost below (author implemented it in Python): Generating integer partitions I'm still trying to learn best practices in ...
3
votes
1answer
65 views

Optimizing quicksort

I created simple quicksort algorithm using iterators. I'm happy with implementation but not with its speed. Profiler tells me that the slowest operation here is ...
2
votes
2answers
80 views

JS to create Table data dynamically

The following codes generate table row dynamically. I wonder if there are better ways of generating the same data. Also instead of manually coding the heading and the table itself, is it possible to ...
1
vote
0answers
52 views

itertools.produce reduced and filtered

I need to generate list of all allowable test combination values of of actor, action and ...
11
votes
3answers
2k views

Decoding assembly instructions in a Game Boy disassembler

I am coding a game boy disassembler in C++. The program (simplified here) converts a vector of byte into an assembly instruction and print it. To do so, it iterates through the vector of bytes (char)...
2
votes
1answer
22 views

Short analogue of Riffle[] accepting two blocks

I have an array of some elements that I need to loop through (i.e. execute some block A on each element) but between them I have also to "clean up" (block ...
1
vote
1answer
42 views

Merging (not removing) duplicated elements in a vector

There's a struct named Player containing name and stat: ...
2
votes
2answers
72 views

A Java Iterable over multiple arrays

GlueArrays is used for iterating over an array of arrays, and it looks like this: Main.java ...
3
votes
2answers
83 views

Infinite and countdown counters

I'm refactoring my scheduler and for one of its triggers I need an endless counter that would automatically restart. Since this is a simple and very common task I don't want to ever have to implement ...
4
votes
3answers
105 views

My implementation of a for_each function that traverses a std::container by some step size integer N

As my answer to Iterating over an odd (even) elements only in a range-based loop, I wrote this function, with the following driver program and output: ...
4
votes
1answer
44 views

Rust version of basic functional prime stream - can this be made less clunky?

I'm looking at implementing the basic functional not-quite-Eratosthenes prime stream in Rust. I like to try it when I start learning a language. Here's the bog standard Haskell version: ...
1
vote
1answer
119 views

Find all starting indices in a string which are anagrams of a word

The task: Given a word W and a string S, find all starting indices in S which are anagrams of W. For example, given that W is "ab", and S is "abxaba", return 0, 3, and 4. My solution: ...
2
votes
1answer
88 views

Iterating over different Objects which are ordered by index number

I am currently working on a bigger project where I found a part of it which seems very ugly to me from the code. I stripped out the algorithm and made a working code, so it can be reviewed. I have ...
1
vote
1answer
298 views

Applying multiple php FilterIterator instances in a cascading fashion

I wrote an implementation of php FilterIterator objects that allows me to apply them in a "cascade" way, so I can finally obtain an array of objects which is the ...