私のリストには、名前とキャンパスID(CWID)が含まれています。どのように私は私のリストにある整数を渡す整数と比較することができますか?私は私がやろうとしていることの下で比較の擬似コードを書いた。C++シングルリンクリストの特定の値へのアクセス
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_;
}
私は上記のコードの内容を達成しようとしています。私は私のリストの特定のアイテムを比較する方法を知りません。ここに私の練習プロジェクト全体があります。コードの巨大な山であり、それは空白の膨大な量でいっぱいだ
#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){
}
}
。あなたはそれをきれいにして、問題の厳密に関連していないものを手元に削除できますか? – tadman
ok about now –
まだデッドスペースが多いし、問題の核心から何かを逸らすミステリーコードもある。 [最小限の自己完結型サンプルの作成方法](https://stackoverflow.com/help/mcve)を読んでください。 – tadman