Here's the problem.
这是问题所在。
Write a function for merging multiple (sorted) linked lists into one sorted linked list. This function should access the elements through Iterator interface (do not access elements through the linked list directly). The arguments to the merge procedure are an array of Iterators and the size of the array. The return value should be another Iterator with an underlying List implementation.
编写一个函数,用于将多个(已排序)链接列表合并到一个已排序的链接列表中。此函数应通过Iterator接口访问元素(不要直接通过链接列表访问元素)。合并过程的参数是迭代器数组和数组的大小。返回值应该是具有基础List实现的另一个Iterator。
Steps:
(1) Implement linked list with iterator interface. Define the Element in the list as below:
(1)用迭代器接口实现链表。在列表中定义元素如下:
typedef struct
{
int idno;
char name[25];
float marks;
} Element;
(a) List createList();
(a)列出createList();
(b) List insert(List L, Element e );
(b)清单插入(清单L,要素e);
(c) Void printList(List L);
(c)Void printList(List L);
(d) iterator initIterator(List L);
(d)迭代器初始化器(列表L);
(e) boolean hasMoreElements(iterator I);
(e)boolean hasMoreElements(iterator I);
(f) iterator moveNext(iterator I);
(f)迭代器moveNext(迭代器I);
(2) Implement Merge function.
(2)实现合并功能。
iterator merge(iterator I[],int size)
This function will merge the elements in all the lists ordered by the attribute “marks”. Merge function should access the list through the iterator functions.
此函数将合并由属性“marks”排序的所有列表中的元素。合并函数应该通过迭代器函数访问列表。
(3) Implement driver function.
(3)实现驱动功能。
Populate the lists from the input files (provided as support). Call the merge function and store the data in resultant merged list to an output file.
填充输入文件中的列表(作为支持提供)。调用合并函数并将结果合并列表中的数据存储到输出文件中。
Support files: test1.txt, test2.txt, test3.txt, test4.txt, test5.txt, test6.txt, test7.txt, test8.txt
支持文件:test1.txt,test2.txt,test3.txt,test4.txt,test5.txt,test6.txt,test7.txt,test8.txt
Deliverables: dataDef.h, mergeOps.c, mergeOps.h, main.c, output.txt
可交付成果:dataDef.h,mergeOps.c,mergeOps.h,main.c,output.txt
Now i dont want the solution for this, but i want to know what an iterator interface is. I have never heard of it before.
现在我不想要解决方案,但我想知道迭代器接口是什么。我以前从未听说过。
And how do i go about implementing linked list with iterator interface.What does it mean?
我如何使用迭代器接口实现链表。这是什么意思?
Also it uses a data type of iterator
what that would be?
它还使用迭代器的数据类型会是什么?
1 个解决方案
#1
4
An iterator is simply a generalized term for something that allows you to traverse a container (like an array, list, etc).
迭代器只是一个通用术语,允许您遍历容器(如数组,列表等)。
From wikipedia,
In computer programming, an iterator is an object that enables a programmer to traverse a container. Various types of iterators are often provided via a container's interface. Though the interface and semantics of a given iterator are fixed, iterators are often implemented in terms of the structures underlying a container implementation and are often tightly coupled to the container to enable the operational semantics of the iterator. Note that an iterator performs traversal and also gives access to data elements in a container, but does not perform iteration (i.e., not without some significant liberty taken with that concept or with trivial use of the terminology). An iterator is behaviorally similar to a database cursor.
在计算机编程中,迭代器是一个使程序员能够遍历容器的对象。通常通过容器的接口提供各种类型的迭代器。虽然给定迭代器的接口和语义是固定的,但迭代器通常是根据容器实现的底层结构实现的,并且通常紧密耦合到容器以启用迭代器的操作语义。请注意,迭代器执行遍历并且还允许访问容器中的数据元素,但不执行迭代(即,没有使用该概念或使用术语的一些重要*)。迭代器在行为上类似于数据库游标。
As your assignment talks about creating an iterator without access the elements directly, you can have a look at Iterator Design Pattern
由于您的任务是关于创建迭代器而不直接访问元素,因此您可以查看迭代器设计模式
More information on Iterator
有关迭代器的更多信息
- Iterator implementation in C
- Iterator pattern in OOP
- Do we still need Iterator design pattern?
- Iterator design pattern in C#
C中的迭代器实现
OOP中的迭代器模式
我们还需要Iterator设计模式吗?
C#中的迭代器设计模式
#1
4
An iterator is simply a generalized term for something that allows you to traverse a container (like an array, list, etc).
迭代器只是一个通用术语,允许您遍历容器(如数组,列表等)。
From wikipedia,
In computer programming, an iterator is an object that enables a programmer to traverse a container. Various types of iterators are often provided via a container's interface. Though the interface and semantics of a given iterator are fixed, iterators are often implemented in terms of the structures underlying a container implementation and are often tightly coupled to the container to enable the operational semantics of the iterator. Note that an iterator performs traversal and also gives access to data elements in a container, but does not perform iteration (i.e., not without some significant liberty taken with that concept or with trivial use of the terminology). An iterator is behaviorally similar to a database cursor.
在计算机编程中,迭代器是一个使程序员能够遍历容器的对象。通常通过容器的接口提供各种类型的迭代器。虽然给定迭代器的接口和语义是固定的,但迭代器通常是根据容器实现的底层结构实现的,并且通常紧密耦合到容器以启用迭代器的操作语义。请注意,迭代器执行遍历并且还允许访问容器中的数据元素,但不执行迭代(即,没有使用该概念或使用术语的一些重要*)。迭代器在行为上类似于数据库游标。
As your assignment talks about creating an iterator without access the elements directly, you can have a look at Iterator Design Pattern
由于您的任务是关于创建迭代器而不直接访问元素,因此您可以查看迭代器设计模式
More information on Iterator
有关迭代器的更多信息
- Iterator implementation in C
- Iterator pattern in OOP
- Do we still need Iterator design pattern?
- Iterator design pattern in C#
C中的迭代器实现
OOP中的迭代器模式
我们还需要Iterator设计模式吗?
C#中的迭代器设计模式