Ok basicly for this assigment we have to make a linked list of size n(user defined). Then have to cout every element in the list. After this we have to ask the user which group of numbers to delete (even numbers/odd numbers) then cout the new list.
ex:
user input n: 5
cout on screen: 1,2,3,4,5
user input: even
cout on screen: 1,3,5
i've got the linked list down fine but the odd/even is confusing me. was trying to do something like:
but not really sure can anyone give some advice please.Code:for(int i = 0; i < n; i++) { if(i % 2 == 0) arr[i] = true; } cout << arr[i] << endl;
Current code is:
Code:#include <iostream> using namespace std; struct Node { int data; Node* next; }; void print(Node* line) { Node* list = line; while(list != NULL) { cout << list->data << ", "; list = list->next; } } void main() { int n; cout << "Enter Positive int:"; cin >> n; Node* head; head = new Node; head->data = 1; head->next = NULL; Node* temp = head; for(int i = 2; i < n; i++) { temp->next = new Node; temp = temp->next; temp->data = i; temp->next = NULL; } cout <<" " << endl; print(head); cout << n << endl; cout <<" " << endl; int choice; cout <<"Even or odd (1/2): "; cin >> choice; if(choice == 1){ //do even } else{ //do odd } while(head != NULL) { temp = head; head = head->next; delete temp; } }
XI Wiki

