#include <iostream>
#include <list>
#include "d_node.h"
usingnamespace std;
template <typename T>
void writeLinkedList(node<T> *front, const string& separator = " ")
{
node<T> *curr;
curr = front;
while (curr != NULL)
{
if(curr->nodeValue != 0 && curr->nodeValue != 1)
{
cout << curr->nodeValue << " ";
}
curr = curr->next;
}
}
template <typename T>
void makeZero(node<T> *front, const T& item)
{
node<T> *curr;
curr = front;
while (curr != NULL)
{
if (curr->nodeValue == item)
{
curr->nodeValue = 0;
}
curr = curr->next;
}
}
int main() {
int i;
cout << "Enter an integer: ";
cin >> i;
node<int> *front = NULL, *newNode;
newNode = new node<int> (1, front);
front = newNode;
for (int k = i; 0 < k; k--)
{
newNode = new node<int> (k, front);
front = newNode;
}
for (int a = 2; a < 1000; a++)
{
for (int b = 2; a*b < i; b++)
{
int count = a*b;
makeZero(front, count);
}
}
writeLinkedList(front, " ");
cout << endl;
}
and this is my main file. It's supposed to access every position and change the value to 0 unless it's not a prime number. However, for some reasons, it does not access the last position.