[السلام عليكم ورحمة الله وبركاته
احتاج مساعدة منكم في data structures , linked list
انا مبتدئه فيه من كم يوم بس اعرف الاساسيات ولم اتعمق
السؤال في المرفقات
الله يجزاكم كل خير يارب , حتى لو مو الحل كامل بس شرح للفكرة عشان افهم
[السلام عليكم ورحمة الله وبركاته
احتاج مساعدة منكم في data structures , linked list
انا مبتدئه فيه من كم يوم بس اعرف الاساسيات ولم اتعمق
السؤال في المرفقات
الله يجزاكم كل خير يارب , حتى لو مو الحل كامل بس شرح للفكرة عشان افهم
تم تعديل هذه المشاركة بواسطة Esraa94 في 12 يوليو 2014 في 01:16
أختي الكريمة ابحثي عن الموضوع إن كنت تريدين الفكرة الرئيسية الانترنت مليء بالشروحات , وهذه إحداها من منتدانا /index.php/topic/274754-%D9%87%D9%8A%D8%A7%D9%83%D9%84-%D8%A7%D9%84%D8%A8%D9%8A%D8%A7%D9%86%D8%A7%D8%AA-%D9%81%D9%8A-%D9%84%D8%BA%D8%A9-%D8%A7%D9%84%D8%B3%D9%8A-%D9%81%D9%87%D8%B1%D8%B3-%D8%A7%D9%84%D8%B3%D9%84%D8%B3%D9%84%D8%A9/
بالتوفيق
كل الشكر لك الحمدلله هذا الموضوع على درايه فيه من قبل وقريته وفهمته يعطيك العافية يارب
ولكن سوالي كيف اقدر اغير بالكود بحيث يناسب السؤال يعني مثلا فقرة الحذف اذا كان الطالب غاب اكثر من 30%
هل يكون مشابه للاساسي بدون تغير واليوزر هو اللي يحدد اسم اللي غاب اكثر من 30% او يجب ان يكون هناك مدخل اخر يبين لي نسبة الغياب ؟
وفقرة اضافة 10 اسماء تكون باضافة Loop / For ?
و update فقرة 5 نستخدم دالة display مرة ثانية بنفس طريقة فقرة 3 ؟
تم تعديل هذه المشاركة بواسطة Esraa94 في 12 يوليو 2014 في 22:32
#include <iostream>
#include <string>
using namespace std;
typedef struct Node
{
int Id;
char name;
Node * next;
};
Node *header = NULL;
void display();
void add_node_at_end();
void delete_end_node();
void delete_front_node();
void add_node_at_front();
int count();
int main(void)
{
const char menu[]="\n\t\t********** Link List operation **********\n"
"\nPlease choose one of the following tasks : "
"\n\t\t1- 1-Create a record of name of 7 student who did not pass data structure course in the previous semester."
"\n\t\t2-Add record of 10 name of students who want to improve their grades. The record should be added at the end of the record. "
"\n\t\t3-View all names"
"\n\t\t4- Delete two students who miss the 30% of the class. The record should be deleted from any position"
"\n\t\t5. Update the record after deleted"
"\n\t\t6-Exit System\n"
">>>> your choice : ";
int choice,c;
cout<<menu;
cin>>choice;
while (choice!=6)
{
switch (choice)
{
case 1:
add_node_at_front();
break;
case 2:
add_node_at_end();
break;
case 3:
display();
break;
case 4:
void delete_specifice_node();
break;
case 5:
display();
break;
default:
cout<<"\n\t### Unacceptibale task abbreviation ###\n";
break;
}
cout<<menu;
cin>>choice;
}
}
void add_node_at_front()
{
Node *temp, *temp2;
temp = new Node;
cout << "Please enter student name and Id who did not pass data structure course in the previous semester: " << endl;
for (int i=1; i<=7 ; i++)
{
cout << "name : " ;
cin >> temp->name;
cout << "ID : " ;
cin >> temp->Id;
}
if (header == NULL)
{
header = temp;
temp->next=NULL;
}
else
{
temp2 = header;
header=temp;
temp->next=temp2;
}
}
void add_node_at_end()
{
Node *temp, *temp2;
temp = new Node;
cout << "Please enter student name and Id who want to improve their grades ";
for (int i=1; i<=10 ; i++)
{
cout << "name : " ;
cin >> temp->name;
cout << "ID : " ;
cin >> temp->Id;
}
temp->next = NULL;
if (header == NULL)
header = temp;
else
{
for ( temp2=header;temp2->next!=NULL;temp2=temp2->next);
temp2->next = temp;
}
}
void display()
{
Node *temp;
for ( temp=header;temp!=NULL;temp=temp->next)
{
cout << "Name : " << temp->name << endl;
cout << "Id : " << temp->Id << endl;
cout << endl;
}
}
void delete_specifice_node()
{
char x;
Node *temp1, *temp2;;
cout<<"Enter the name that you want delete it: ";
cin>>x;
if (header!=NULL)
{
if(header->next==NULL&&header->name==x)
header=NULL;
else if(header->name==x)
{
temp2=header;
header=header->next;
delete temp2;
}
else
{
for (temp1=header,temp2=header->next;temp2!=NULL&&temp2->name!=x;temp1=temp1->next,temp2=temp2->next);
if (temp2!=NULL)
{
if(temp2->next=NULL)
temp1->next=NULL;
else
{
temp1->next=temp2->next;
delete temp2;
}
}
}
}
}أتمنى من أهل الخبرة تصحيح اخطائي بالكود وشاكرة لكم
تم تعديل هذه المشاركة بواسطة Esraa94 في 13 يوليو 2014 في 03:36
اولا نوع المتغير المستخدم لتخزين الاسم غير صحيح لابد من استخدام char [] او char*
typedef struct Node
{
int Id;
char name[50];
Node * next;
};ثانيا الدالتين : add_node_at_front و add_node_at_end لا يوجد داعي للfor فيهما
ثالثا: delete_specifice_node نفس مشكلة الاسم في قراءة الاسم المراد حذفه و كذالك طريقة مقارنة المتغير من نوع char* او char[] ليست بالمساواة العادية هناك عدة طرق يمكنك البحث عن الانسب لما درستيه والا يفضل ان يكون المقارنة بالID لانه رقم