我一直在研究循环双链表。决定创建一个类并使用标题。我是 C++ 的新手,所以我查看了如何实现它。我不确定我是否在列表中正确实现了结构节点。
编译 Clist.cpp 文件后,我收到此错误。
(.text+0xd2): undefined reference to `WinMain@16' collect2: ld returned 1 exit status Process terminated with status 1 (0 minutes, 1 seconds) 1 errors, 0 warnings d:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\libmingw32.a(main.o):main.c|| undefined reference to `WinMain@16'|
class Clist { công cộng: Clist(char); virtual ~Clist(); Node *head; // current node that is being pointed to kích thước int; bool isEmpty(); void addNodeBefore(char); // inserted before head void addNodeAfter(char); // inserted after head void addNodeBeforeData(char, Node*);// Same as above, inserted before/after a specific node void addNodeAfterData(char, Node*); void out(bool); // Prints the list, true starts from beginning, false starts from end void setData(char); void setPrev(Node*); void setNext(Node*); bool findData(char); // Searches through the list to find the char void deleteData(char, bool);
};
#endif // CLIST_H
--
#include "Clist.h" #include #include sử dụng không gian tên std;
Clist::Clist(char d) { head = new Node(d, NULL, NULL); head->next = head->prev = head; size = 1;
if (counter > 0) { cout << "'" << search << "' was found " << counter << " time(s)" << endl; trả về sự thật; }else { cout << "'" << search << "' was not found" << endl; trả về sai; } }
void Clist::deleteData(char search, bool all) // If true, it will delete all nodes with the same search { // If false, it will delete the first Node only Node *tmp = head; while(tmp) { if(tmp->data == search) { cout << "Deleting " << search << endl; tmp->prev->next = tmp->next; tmp->next->prev = tmp->prev; if (false) trở lại; } tmp = tmp->next;
} }
--
#include #include #include "Clist.h" sử dụng không gian tên std;
int main(int argc, char* argv[]) {
char s[]="abcfdefghijklmgnopqrsatuvwxyz";
Clist *list; // ptr to head of list Node *curr; // ptr to current node of the list
// call constructor and initialize first Node list = new Clist(s[0]);
for(size_t i=1; i < strlen(s); i++) // create the rest of the linked list list->addNodeAfter(s[i]);
Như hiện tại, câu hỏi này không phù hợp với định dạng Hỏi & Đáp của chúng tôi. Chúng tôi mong đợi câu trả lời sẽ được hỗ trợ bởi các sự kiện, trích dẫn hoặc chuyên môn, nhưng câu hỏi có thể gây ra tranh luận, tranh luận, bỏ phiếu hoặc thảo luận mở rộng. Nếu bạn cảm thấy vấn đề này có thể được cải thiện và có thể mở lại, hãy truy cập
Tôi là một lập trình viên xuất sắc, rất giỏi!