Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include using namespace std; struct node { int data; node *next; }; class IntegerLinkedList { private: node *head; public: IntegerLinkedList() { head = NULL; }
#includeusing namespace std; struct node { int data; node *next; }; class IntegerLinkedList { private: node *head; public: IntegerLinkedList() { head = NULL; } void addFront(int value) { node *temp = new node; temp->data = value; temp->next = NULL; if (head == NULL) { head = temp; temp = NULL; } else { temp->next = head; head = temp; } } int countPositive() { int count = 0; node *trav = head; while (trav != NULL) { if (trav->data>0) count++; trav = trav->next; } return count; } }; #include #include //#include "IntegerLinkedList.h" using namespace std; int main() { IntegerLinkedList mylist; cout << "Enter number of integers : "; int n, value; cin >> n; cout << "Enter " << n << " integers" << endl; for (int i = 0; i < n; i++) { cin >> value; mylist.addFront(value); } cout << "countPositive: " << mylist.countPositive() << endl; system("pause"); // comment/uncomment if needed }
Hello, could you please add a function to fine the smallestPositive # like example .... -3 5 -6 8 7 the smallest positive is 5.
Thank you
Best
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started