Viết 1 chương trình game đơn giản như sau: - Chương trình cho phép người dùng (user)…
- User
Viết 1 chương trình game đơn giản như sau:
-
Chương trình cho phép người dùng (user) chọn thực hiện 1 thao tác nào đó từ Menu, trả về kết quả thực hiện thao tác đó.
-
Viết hàm cho phép thêm các giá trị y vào sau (hoặc vào trước) các giá trị x có trong danh sách. Nếu có nhiều giá trị x được lưu trữ trong danh sách thì chèn thêm giá trị y vào sau tất cả các giá trị x đó. Nếu danh sách không chứa x thì không thêm gì cả và xuất thông báo theo câu lệnh: cout << "\nCan't find the value "<<x;
INPUT & OUTPUT
- Theo template/###Begin banned keyword - each of the following line if appear in code will raise error. regex supported define include using ###End banned keyword/
#include using namespace std;
struct DNode { int info; DNode *pNext, *pPrev; };
struct DList { DNode *pHead, *pTail; };
//###INSERT CODE HERE -
int main() { DList L; init(L); int x,y,choice;
cout<<"MENU:"; cout<<"\n1. Create a DList"; cout<<"\n2. Print the DList"; cout<<"\n3. Insert a value at the front"; cout<<"\n4. Insert a value at the end"; cout<<"\n5. Insert a value after a given value (only for the first value found)"; cout<<"\n6. Insert a value before a given value (only for the first value found)"; cout<<"\n7. Insert a value after a given value (for all the same values)"; cout<<"\n8. Insert a value before a given value (for all the same values)"; cout<<"\n20. Exit"<<endl; while(true) { cout<<"\n\t\tPLEASE SELECT YOUR CHOICE: "; cin>>choice; switch(choice) { case 1: cout<<"\nEnter your positive integers until you enter -1 to finish: "; createList(L); break; case 2: cout<<"\nYour current DList: "; printList(L); break; case 3: cout<<"\nEnter a number: "; cin>>x; addHead(L,x); break; case 4: cout<<"\nEnter a number: "; cin>>x; addTail(L,x); break; case 5: cout<<"\nEnter two numbers: "; cin>>x>>y; addAfter(L,x,y); break; case 6: cout<<"\nEnter two numbers: "; cin>>x>>y; addBefore(L,x,y); break; case 7: cout<<"\nEnter two numbers: "; cin>>x>>y; addAfterMulti(L,x,y); break; case 8: cout<<"\nEnter two numbers: "; cin>>x>>y; addBeforeMulti(L,x,y); break; case 20: cout<<"\nGOOD BYE"; return 0; } } return 0;}
-
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.