1. 程式人生 > 其它 >求助:error ‘ListNode’ does not name a type

求助:error ‘ListNode’ does not name a type

devc++編譯出錯

#include<iostream>
using namespace std;
class Solution{
	public:
		ListNode* getKthFromEnd(ListNode* head, int k){
			int count = 0;
			int length = 1;
			ListNode via;
			via = head;
			while(via->next != null){
				via = via->next;
				length++;
			}
			while(count != length -
k){ head = head->next; count++; } return head; } }; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} };

出錯資訊

導師讓學c++,求助各位前輩幫忙指正錯誤!