Skip to content

Linked_listC++ #59

Description

@BaraAlqady123

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{
node
prev,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;}
node
temp=head;
while(temp!=NULL){
cout<data<<"\t";
temp=temp->next;}}
//دالة اضافة قيمة معينة الى موقع معين
void insrt_by_pos(int pos,int val){
node* newnode=new node;
newnode->data=val;
newnode->next=NULL;
if(pos==0){
newnode->next=head;
head=newnode;}
else{
nodetemp=head;
for(int i=0;i<pos-1&&temp->next!=NULL;i++ )
temp=temp->next;
newnode->next=temp->next;
temp->next=newnode;}}
//دالة حذف قيمة في موقع معين
void delete_by_pos(int pos){
if(head==NULL){
cout<<"no element in linked list..\n";
return;}
if(pos==0){
node
temp=head;
head=head->next;
delete temp;}
else {
nodetemp=head;
for(int i=0;i<pos-1&&temp->next!=NULL;i++)
temp=temp->next;
if(temp->next==NULL){
cout<<"ERORR enter corect position...\n";
return;}
node
temp2=temp->next;
temp->next=temp->next->next;
delete temp2;}}
//دالة عرض القائمة بالعكس
void revers(){
if(head==NULL){
cout<<"no element in linked list...\n";
return;}
node* prev=NULL;
nodecurr=head;
node
next=NULL;
while(curr!=NULL){
next=curr->next;
curr->next=prev;
prev=curr;
curr=next;}
head=prev;}};

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions