السلام عليكم و رحمة الله و بركاته
اخوتي الكرام ارجو المساعدة في تمرين لم اجد أين الخطأ في الكود
التمرين فقط عباره عن doubly linked list تحتوي على معلومتين احداهما كلمة و التانيه ترجمتها و طبعا 2 pointers لربط العقد ببعضها
مطلوب function تقوم باضافة عقده و اخرى تحذف عقده و اخرى للعرض
#include<iostream>
#include<conio.h>
#include<cstdlib>
using namespace std;
typedef struct Trans{
char word[20];
char translation[20];
struct Trans*next;
struct Trans*prev;
}T;
/**************************/
/* Add */
/**************************/
void Add(T* head , T* queue){
T* node = new T;
cout<<"Give a word: ";
cin>>node->word;
cout<<"Give its translation: ";
cin>>node->translation;
if(head == NULL){ //case Empty list
node->prev = NULL;
node->next = NULL;
head = node;
queue = node;
}else{
node->prev = queue;
node->next = NULL;
queue->next = node;
queue = node;
}
}
/**************************/
/* Display */
/**************************/
void Display(T* head){
T* node = head;
if(courant != NULL){
cout<<node->word<<" ---------> "<<node->translation<<endl;
Display(node->next);
}else{
cout<<"Empty list!";
}
}
/**************************/
/* Remove */
/**************************/
void Remove(T* head , char w[20]){
T* node = head;
if(head == NULL){
cout<<"Empty list!" ;
}else{
while((node != NULL)&&(node->word != w)){
node = node->next;
}
if(node->word == w){
node->prev = node->next;
free(node);
}else{
cout<<"End of list!";
}
}
}
/**************************/
/* Main */
/**************************/
int main(){
T* head = NULL;
T* queue = head;
int choice;
char w , rep;
cout<<"========= MENU ========"<<endl;
cout<<"Add new word (1)"<<endl;
cout<<"Display all words (2)"<<endl;
cout<<"Remove a word (3)"<<endl;
cout<<"======================="<<endl;
do{
cout<<"enter a choice: ";
cin>>choice;
switch(choice){
case 1:
Add(head , queue);
break;
case 2:
Display(head);
break;
case 3:
//Remove(head , w);
//break;
default:
cout<<"Error"<<endl;
break;
}
cout<<"Other choice (y/n)? ";
cin>>rep;
}while(rep != 'n');
getch();
return 0;
}
