0
無法識別在鏈接列表類中創建鏈接列表插入函數時的錯誤編譯器給出了「錯誤:在聲明之前的限定id'('token但似乎像所有的括號都正確放置。創建鏈接列表插入功能,但代碼沒有運行
#include <iostream>
using namespace std;
void additem();
void deleteitem();
void searchitem(int x);
struct student{
int data;
int * next;
};
student * head;
student * curr;
int main()
{
int x;
cout << "To add item type 1" << endl;
cin >> x;
switch(x)
{
case 1:
additem();
}
return 0;
}
void additem()
{
student * temp;
if(head == NULL)
{
temp = new student;
head = temp;
curr = temp;
temp->next = NULL;
cout << "Enter data" << endl;
cin >> temp->data << endl;
}
else if(head != NULL)
{
temp = new student;
curr->next = temp;
curr = temp;
temp->next = NULL;
cout << "Enter data" << endl;
cin >> temp->data ;
}
else{
break;
}
}
仍然沒有工作 –
@MAhmadRana現在你的代碼是什麼樣的,你究竟在哪裏得到了錯誤在裏面? – 1201ProgramAlarm
我編輯了代碼 –