يا شباب انا امتحاني بعد يومين واانا بدرس مادة هياكل البيانات
موضوع القوائم المتصلة " linked list " مجنني مش فاهمه خلاص ليا يومين بحاول استوعبه برضوا مش فاهمه
فهمتوا بطريقة لقيت دكتور المادة ماشي بطريقة تانية
انا بجد قلقان اوي ونفسي افهم الموضوع ده لانه جي في العملي
ياريت تساعدوني بشرح بسيط بالعربي بس يكون مبسط
واقل حاجة ممكن تساعدوني بيها انكم تشرحولي الكود ده لان الدكتور ماشي بطريقة غبية في اكواده
والكود ده يعتبر فيه كل العمليات اللي مقررة علينا
ياريت حد يتكرم ويشرحولي
#include <iostream>
//preprocessor directive
using namespace std;
struct NodeType
{
int info;
NodeType* next;
};
NodeType *listData;
int length;
void create()
{
length = 0 ;
listData = NULL;
}
int LengthIs( )
{
return length;
}
bool IsFull(NodeType *location)
{
if(location == NULL)
{
return true;
}
else
return false;
}
void insertItem(int item)
{
NodeType *location ;
location = new NodeType;
if (IsFull(location ))
cout << "the memory is full";
else
{
location->info = item ;
location->next = listData ;
listData = location ;
length++ ;
}
}
void DeleteItem(int item)
{
NodeType* preLocation = NULL;
NodeType* location = listData;
if(item == location->info)
listData = location->next;
else
{
preLocation = location;
location = location->next;
while(item != location->info)
{
preLocation = location;
location=location->next;
}
preLocation->next = location->next;
}
delete location;
length--;
}
void MakeEmpty( )
{
NodeType* tempPtr;
while(listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}
}
void FindItem(int item,bool &found, NodeType *currentPos)
{
bool moreToSearch ;
currentPos= listData;
found = false ;
moreToSearch = ( currentPos != NULL ) ;
while ( moreToSearch && !found )
{
if ( item == (currentPos ->info ))
found = true ;
else
{
currentPos = currentPos ->next ;
moreToSearch = (currentPos != NULL) ;
}
}
}
void Display()
{
NodeType* tempPtr = listData;
while(tempPtr!= NULL)
{
cout<< tempPtr-> info << endl;
tempPtr = tempPtr ->next;
}
}
void main()
{
create();
int x;
int k;
cout << "Enter the number of item in Linked List: ";
cin >> k;
for (int i = 0; i < k; i++)
{
cout << "Please, Enter Number: ";
cin >> x;
insertItem(x);
}
Display();
cout << endl << endl;
}ياريت في اسرع وقت لان الامتحان بعد بكرة :mellow:

