LinkedList
LinkedList copied to clipboard
Linked_listC++
class linked_list{ struct node{//عملنا العقدة حقنا int data; node* next;}; node* head=NULL; public: // دالة اضافة عنصر الى اخر القائمة void apend_to_last(int val){ node* newnode=new node; newnode->data=val; newnode->next=NULL; if(head==NULL) head=newnode; else{ node* temp=head; while(temp->next!=NULL) temp=temp->next; temp->next=newnode;}} //دالة البحث عن القيمة التي ادخلها المستخدم وحذفها void delete_by_val(int val){ if(head==NULL) {cout<<"no elements in linked list...\n"; return;}
nodetemp;
temp=head;
if(temp->data==val){
head=head->next;
delete temp;}
else{
nodeprev,temp;
prev=temp=head;
while(temp!=NULL&&temp->data!=val){
prev=temp;
temp=temp->next;}
if(temp==NULL)
{cout<<"not found \n";
return;}
else{
prev->next=temp->next;
delete temp;}}}
//دالة عرض عناصر القائمة المتصلة
void display(){
if(head==NULL){
cout<<"no element in linked list...\n";
return;}
nodetemp=head;
while(temp!=NULL){
cout<