[C++]Doubly Linked List with Iterator

During the study week I tried to implement an integer list using Visual C++. My goal is to be as similar to as the list and iterator in the standard library. My goal is to simulate the implementation of the standard library list and iterator.

There are many people having issues with insertion and deletion of the iterator. In order to delete the boundaries of the list, the iterator need to have the access of the front and back of the list. According to the standard iterator, it does not have such a function:

A sample source main is:

#include "DoublyLinkedList.h"
#include
using namespace std;
int main(){
	DoublyLinkedList dll;
	dll.pushFront(12);
	dll.pushFront(11);
	dll.pushFront(10);
	dll.pushBack(13);
	dll.pushBack(14);
	dll.pushFront(9);
	while (!dll.isEmpty()){
		cout << "[DLL]Element:" << dll.getBack() << endl;
		dll.popBack();
	}
	int a[] = {55,66,77,88,99};
	DoublyLinkedList dll2(a, a + 5);
	for (DoublyLinkedList::iterator it = dll2.begin(); it != dll2.end(); ++it){
		cout << "[DLL2]Element:" << *it << endl;
	}
	return 0;
}

Output:

[DLL]Element:14
[DLL]Element:13
[DLL]Element:12
[DLL]Element:11
[DLL]Element:10
[DLL]Element:9
[DLL2]Element:55
[DLL2]Element:66
[DLL2]Element:77
[DLL2]Element:88
[DLL2]Element:99

Source Code(Please feel free to fork & contribute): https://github.com/Parthas-Menethil/DoubleLinkedList

Leave a Reply

Your email address will not be published. Required fields are marked *