My list contains a name and a campus id(CWID). How can i compare the cwid that is in my list to the integer i am passing in? I wrote the psuedo code of the comparison below of what i am trying to do.
void check_cwid(studentList& list, int cwid) {
studentNode *p = list.head_;
while(p != nullptr){
//Something like this
if *p.cwid() == cwid
//do something
p = p->next_;
}
I am trying to accomplish what is in the code above. I just dont know how to compare specific items in my list. Here is my entire practice project below.
#include <iostream>
using namespace std;
class student {
public:
student(const string& sname = "", int cwid = 0) : sname_(sname), cwid_(cwid) {}
string sname() const {return sname_;}
int cwid() const {return cwid_;}
friend ostream& operator <<(ostream& os, student st){
return os << endl << st.sname_ << endl << st.cwid_ << endl;
}
private:
string sname_;
int cwid_;
};
struct studentNode {
studentNode(const string& sname, int cwid, studentNode* next=nullptr) :st_(sname, cwid), next_(next) {}
studentNode(student& st, studentNode* next=nullptr) : st_(st), next_(next) {}
friend ostream& operator << (ostream& os, studentNode node) {
return os << node.st_;
}
studentNode* next_;
student st_;
};
struct studentList {
studentList() : head_(nullptr), size_(0) {}
studentNode* head_;
size_t size_;
};
///******************** what im trying to do
void check_cwid(studentList& list, int cwid) {
studentNode *p = list.head_;
while(p != nullptr){
}
}