SlideShare una empresa de Scribd logo
1 de 110
LINKED LIST
PRESENTED BY:

                Javeria
             (11-arid-3303)
                 MIT-3
   University Institute of Information
               Technology,
       Rawalpindi (UIIT, UAAR)
INTRODUTION
   Link List is an ordered collection of elements
    called nodes. The nodes are connected by
    pointer.

   Each node has two parts
    1) Data Field – Stores data of the node. Same data
      type
    2) Link Field – Store address of the next node
                    ( i.e. Link to the next node)
                                 NEXT

         NODE :

                      DATA
ARRAY VS. LINK LIST
       Aspect              Array                        Link List

Size             Fixed size.                   Grow and contract
                                                 according to insertions
                                                 and deletions.

Storage          Static: It’s location is      Dynamic: It’s node is
capacity        allocated during compile         located during run time.
                time.
Accessing the    Direct or random access       Sequential access
element           method.                        method.
                 Specify the array index or    Traverse starting from the
                  subscript.                     first node in the list by
                                                 pointer.



                                                                  4
SINGLY LINK LIST
IMPLEMENTATION IN
STACKS:

            A          B            C   top


IMPLEMENTATION IN LINEAR
QUEUE:
     front A            B           C   rear



IMPLEMENTATION IN CIRCULAR QUEUE:

            A          B            C   rear




                DOUBLY LINK LIST

        A                   B             C    rear
LINKED LIST
IMPLEMENTATION

   Stacks
   Linear Queue
   Circular Queue
Functions

◦ We will discuss the following functions in
above three data structures:
    Insertion
    Deletion
    Display
    Search
LINK LIST IMPLEMENTATION
        OF STACKS
Defining the linked list data
structure:
  struct node
  {
       int data;
       node *next;
  };


                     Data   next

                        node
STACK CLASS

class stack
{
 public:
  node * top;
  stack( )
  {               top
      top=NULL;
  }
Push method
void push(int x)
{
    node * ptr=new node;
                           top
    ptr->data=x;
    ptr->next=top;
    top=ptr;
}
Push method
void push(int x)           ptr
{
    node * ptr=new node;
                             top
    ptr->data=x;
    ptr->next=top;
    top=ptr;
}
Push method
void push(int x)               ptr
{                          x
    node * ptr=new node;
                                 top
    ptr->data=x;
    ptr->next=top;
    top=ptr;
}
Push method
void push(int x)               ptr
{                          x
    node * ptr=new node;
                                 top
    ptr->data=x;
    ptr->next=top;
    top=ptr;
}
Push method
void push(int x)               ptr
{                          x
    node * ptr=new node;
                                 top
    ptr->data=x;
    ptr->next=top;
    top=ptr;
}
Push method
void push(int x)
{                              top
                               ptr
    node * ptr=new node;
    ptr->data=x;           x
    ptr->next=top;
    top=ptr;
}
-   All nodes are connected to each other through
    pointers
-   Link of the first node is NULL pointer denoted by X
-   Null pointer indicates the start of the stack list
                               top

                           D


                           C


                           B



                           A
Pop Method
int pop()
{
                               top
    if(top==NULL)
     {
     cout<<"nlist emptyn";   D
     return;
     }
                               C
    else
     {
     int temp=top->data;
     node* ptr=top;            B
     top=top->next;
     delete ptr;
     return temp;              A
     }
}
Pop Method
int pop()
{                              top   temp=D
    if(top==NULL)
     {
     cout<<"nlist emptyn";   D
     return ;
     }
                               C
    else
     {
     int temp=top->data;
     node* ptr=top;            B
     top=top->next;
     delete ptr;
     return temp;              A
     }
}
Pop Method
int pop()
                                   ptr
{                              top       temp=D
    if(top==NULL)
     {
     cout<<"nlist emptyn";   D
     return ;
     }
                               C
    else
     {
     int temp=top->data;
     node* ptr=top;            B
     top=top->next;
     delete ptr;
     return temp;              A
     }
}
Pop Method
int pop()
{                              ptr
                                         temp=D
    if(top==NULL)
     {                         D
     cout<<"nlist emptyn";
     return ;                      top
     }
                               C
    else
     {
     int temp=top->data;
     node* ptr=top;            B
     top=top->next;
     delete ptr;
     return temp;              A
     }
}
Pop Method
int pop()
{                              ptr
                                         temp=D
    if(top==NULL)
     {                         D
     cout<<"nlist emptyn";
     return ;                      top
     }
                               C
    else
     {
     int temp=top->data;
     node* ptr=top;            B
     top=top->next;
     delete ptr;
     return temp;              A
     }
}
Display Method
void display()
{
    node * temp;
                                     top
    temp=top;
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";
        return;                  C
    }
    while(temp!=NULL)
    {                            B
        cout<<temp->data<<" ";
        temp=temp->next;
    }                            A
}
Display Method
void display()
{
    node * temp;                     tem
                                     top
                                     p
    temp=top;
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";
        return;                  C
    }
    while(temp!=NULL)
    {                            B
        cout<<temp->data<<" ";
        temp=temp->next;
    }                            A
}
Display Method
void display()
{
    node * temp;                     tem
                                     top
                                     p
    temp=top;                              display D
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";
        return;                  C
    }
    while(temp!=NULL)
    {                            B
        cout<<temp->data<<" ";
        temp=temp->next;
    }                            A
}
Display Method
void display()
{
    node * temp;
                                     top
    temp=top;
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";          tem
                                      p
        return;                  C
    }
    while(temp!=NULL)
    {                            B
        cout<<temp->data<<" ";
        temp=temp->next;
    }                            A
}
Display Method
void display()
{
    node * temp;
                                     top
    temp=top;
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";          tem
                                      p
        return;                  C          display C
    }
    while(temp!=NULL)
    {                            B
        cout<<temp->data<<" ";
        temp=temp->next;
    }                            A
}
Display Method
void display()
{
    node * temp;
                                     top
    temp=top;
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";
        return;                  C
    }
                                      tem
    while(temp!=NULL)                 p
    {                            B
        cout<<temp->data<<" ";
        temp=temp->next;
    }                            A
}
Display Method
void display()
{
    node * temp;
                                     top
    temp=top;
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";
        return;                  C
    }
                                      tem
    while(temp!=NULL)                 p     display B
    {                            B
        cout<<temp->data<<" ";
        temp=temp->next;
    }                            A
}
Display Method
void display()
{
    node * temp;
                                     top
    temp=top;
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";
        return;                  C
    }
    while(temp!=NULL)
    {                            B
        cout<<temp->data<<" ";
                                       tem
        temp=temp->next;
                                       p
    }                            A
}
Display Method
void display()
{
    node * temp;
                                     top
    temp=top;
    if(top==NULL)
                                 D
    {
        cout<<"stack empty";
        return;                  C
    }
    while(temp!=NULL)
    {                            B
        cout<<temp->data<<" ";
                                       tem
        temp=temp->next;
                                       p     display A
    }                            A
}
Display Method
void display()
{
    node * temp;
                                      top
    temp=top;
    if(top==NULL)
                                  D
    {
        cout<<"stack empty";
        return;                   C
    }
    while(temp!=NULL)
    {                             B
        cout<<temp->data<<" ";
        temp=temp->next;
    }                             A
}
                                 temp = NULL
Search Method
void search(int x)
{
   int a=0; //index calculated from top
   node * temp=top;                                 x=B
   while(temp!=NULL)                                a=0
   {                                          top
        if(temp->data==x)
        {                                 D
           cout<<"found at index "<<a;
           break;
         }
        else                              C
        {
         temp=temp->next;
         a++;                             B
        }
    }
   if(temp==NULL)
   cout<<“value not found";               A
}
};
Search Method
void search(int x)
{
   int a=0; //index calculated from top
   node * temp=top;                                 x=B
   while(temp!=NULL)                          tem
                                                    a=0
   {                                          top
                                              p
        if(temp->data==x)
        {                                 D
           cout<<"found at index "<<a;
           break;
         }
        else                              C
        {
         temp=temp->next;
         a++;                             B
        }
    }
   if(temp==NULL)
   cout<<“value not found";               A
}
};
Search Method
void search(int x)
{
   int a=0; //index calculated from top
   node * temp=top;                                 x=B
   while(temp!=NULL)                                a=1
   {                                          top
        if(temp->data==x)
        {                                 D
           cout<<"found at index "<<a;
           break;                             tem
         }                                    p
        else                              C
        {
         temp=temp->next;
         a++;                             B
        }
    }
   if(temp==NULL)
   cout<<“value not found";               A
}
};
Search Method
void search(int x)
{
   int a=0; //index calculated from top
   node * temp=top;                                 x=B
   while(temp!=NULL)                                a=2
   {                                          top
        if(temp->data==x)
        {                                 D
           cout<<"found at index "<<a;
           break;
         }
        else                              C
        {
                                              tem
         temp=temp->next;
                                              p
         a++;                             B
        }
    }
   if(temp==NULL)
   cout<<“value not found";               A
}
};
Search Method
void search(int x)
{
   int a=0; //index calculated from top
   node * temp=top;                                            x=B
   while(temp!=NULL)                                           a=2
   {                                                     top
        if(temp->data==x)
        {                                            D
           cout<<"found at index "<<a;
           break;
         }
        else                                         C
        {
                                                         tem
         temp=temp->next;
                                                         p
         a++;                             found at   B
        }                                  index 2
    }
   if(temp==NULL)
   cout<<“value not found";                          A
}
};
Main Method
                                          case 2:
void main()                               y=s.pop();
{clrscr();                                if(y!=NULL)
int n, a, y, z;                           cout<<"nvalue popped is: "<<y;
int e=0;                                  break;
stack s;                                  case 3:
   do                                     s.display();
   {cout<<"npress 1 to push";            break;
   cout<<"npress 2 to pop";              case 4:
   cout<<"npress 3 to display";          cout<<“enter value to search?”;
   cout<<“n press 4 to search”;          cin>>z;
   cout<<"npress 5to exitn";            s.search(z);
   cin>>n;                                break;
   switch(n)                              case 5:
    {                                     e=1;
   case 1:                                break;
   cout<<"enter a number";                }
   cin>>a;                             } while(e==0);
   s.push(a);                      }
   break;
TIME COMPLEXITY
    “Time Complexity is a measure of the amount
    of time required to execute an algorithm.”

   Push
    ◦ Best Case: O(1)
    ◦ Worst Case: O(1)
   Pop
    ◦ Best Case: O(1)
    ◦ Worst Case: O(1)
   Search
    ◦ Best Case: O(1)
    ◦ Worst Case: O(n)
LINK LIST
IMPLEMENTATION OF
   LINEAR QUEUE
Defining the linked list data
structure:
 struct node
 {
      int data;
      node *next;
 };


                    Data   next

                       node
Class Linear Queue
class linearQueue
{
 public:
   node *rear;
   node *front;
   linearQueue()
                     rear
   {                 front
       rear=NULL;
       front=NULL;
   }
Insert Method
void insert(int x)      rear
                        front
{
    node * ptr=new
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
    {
      rear->next=ptr;
    }
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
void insert(int x)      rear
                        front   ptr
{
    node * ptr=new
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
    {
      rear->next=ptr;
    }
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
void insert(int x)      rear
                        front   ptr
{
    node * ptr=new              x
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
    {
      rear->next=ptr;
    }
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
void insert(int x)      rear   front
                               ptr
{
    node * ptr=new             x
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
    {
      rear->next=ptr;
    }
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
void insert(int x)      rear   front
                               ptr
{
    node * ptr=new             x
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
    {
      rear->next=ptr;
    }
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
                        rear
void insert(int x)      front
{                       ptr
    node * ptr=new      x
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
    {
      rear->next=ptr;
    }
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
void insert(int x)
{
    node * ptr=new
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
                        rear
    {                   front   ptr
      rear->next=ptr;
    }                   A ptr   x
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
void insert(int x)
{
    node * ptr=new
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
                        rear
    {                   front   ptr
      rear->next=ptr;
    }                   A       x
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
void insert(int x)
{
    node * ptr=new
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else
                        rear
    {                   front   ptr
      rear->next=ptr;
    }                   A ptr   x
    ptr->next=NULL;
    rear=ptr;
}
Insert Method
void insert(int x)
{
    node * ptr=new
       node;
    ptr->data=x;
    if(rear==NULL)
    {
      front=ptr;
    }
    else                        rear
    {                   front   ptr
      rear->next=ptr;
    }                   A ptr   x
    ptr->next=NULL;
    rear=ptr;
}
Remove Method
int remove()
{   if(rear==NULL)
    {                                rear    temp= A
                                     front
        cout<<"nlist emptyn";
        return 0;                    A
    }
    else
    {
        int temp=front->data;
        node* ptr=front;
        if(front->next==NULL)
             { rear=NULL; }
        else
              { front=ptr->next; }
        delete ptr;
        return temp;
    }
}
Remove Method
int remove()
                                             temp= A
{   if(rear==NULL)                   ptr
    {                                rear
                                     front
        cout<<"nlist emptyn";
        return 0;                    A
    }
    else
    {
        int temp=front->data;
        node* ptr=front;
        if(front->next==NULL)
             { rear=NULL; }
        else
              { front=ptr->next; }
        delete ptr;
        return temp;
    }
}
Remove Method
int remove()
                                             temp= A
{   if(rear==NULL)
                                     ptr
    {
                                     front     rear
        cout<<"nlist emptyn";
        return 0;                    A
    }
    else
    {
        int temp=front->data;
        node* ptr=front;
        if(front->next==NULL)
             { rear=NULL; }
        else
              { front=ptr->next; }
        delete ptr;
        return temp;
    }
}
Remove Method
int remove()
                                             temp= A
{   if(rear==NULL)
                                     ptr
    {
                                     front     rear
        cout<<"nlist emptyn";
        return 0;                    A
    }
    else
    {
        int temp=front->data;
        node* ptr=front;
        if(front->next==NULL)
             { rear=NULL; }
        else
              { front=ptr->next; }
        delete ptr;
        return temp;
    }
}
Remove Method
int remove()
{   if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;
    }
    else
    {
        int temp=front->data;        temp=A
        node* ptr=front;
        if(front->next==NULL)
                                      ptr
             { rear=NULL; }           front   rear
        else
                                     A        B
              { front=ptr->next; }
        delete ptr;
        return temp;
    }
}
Remove Method
int remove()
{   if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;
    }
    else
    {
        int temp=front->data;        temp=A
        node* ptr=front;
        if(front->next==NULL)                 front
                                      ptr
             { rear=NULL; }                   rear
        else
                                     A        B
              { front=ptr->next; }
        delete ptr;
        return temp;
    }
}
Remove Method
int remove()
{   if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;
    }
    else
    {
        int temp=front->data;        temp=A
        node* ptr=front;
        if(front->next==NULL)                 front
                                      ptr
             { rear=NULL; }                   rear
        else
                                     A        B
              { front=ptr->next; }
        delete ptr;
        return temp;
    }
}
Display Method
void display()
{
    if(rear==NULL)
    {
        cout<<"list empty";
        return;
    }
    cout<<"data in nodes of link
      list:t";
    node *temp=front;
    while(temp!=NULL)
    {
        cout<<temp->data<<" ";
        temp=temp->next;
                                 front       rear
    }
                                 A       B   C
}
Display Method
void display()
{
    if(rear==NULL)
    {
        cout<<"list empty";
        return;
    }
    cout<<"data in nodes of link
      list:t";
    node *temp=front;
    while(temp!=NULL)
    {
        cout<<temp->data<<" ";
        temp=temp->next;       temp
                               front       rear
    }
                               A       B   C
}
Display Method
void display()
{
    if(rear==NULL)
    {
        cout<<"list empty";
        return;
    }
    cout<<"data in nodes of link
      list:t";
    node *temp=front;
    while(temp!=NULL)                      display A
    {
        cout<<temp->data<<" ";
        temp=temp->next;       temp
                               front             rear
    }
                               A       B        C
}
Display Method
void display()
{
    if(rear==NULL)
    {
        cout<<"list empty";
        return;
    }
    cout<<"data in nodes of link
      list:t";
    node *temp=front;
    while(temp!=NULL)
    {
        cout<<temp->data<<" ";
        temp=temp->next;                     temp
                                 front              rear
    }
                                 A       B          C
}
Display Method
void display()
{
    if(rear==NULL)
    {
        cout<<"list empty";
        return;
    }
    cout<<"data in nodes of link
      list:t";
    node *temp=front;
    while(temp!=NULL)                               display B
    {
        cout<<temp->data<<" ";
        temp=temp->next;                     temp
                                 front                   rear
    }
                                 A       B               C
}
Display Method
void display()
{
    if(rear==NULL)
    {
        cout<<"list empty";
        return;
    }
    cout<<"data in nodes of link
      list:t";
    node *temp=front;
    while(temp!=NULL)
    {
        cout<<temp->data<<" ";
        temp=temp->next;                     temp
                                 front        rear
    }
                                 A       B   C
}
Display Method
void display()
{
    if(rear==NULL)
    {
        cout<<"list empty";
        return;
    }
    cout<<"data in nodes of link
      list:t";
    node *temp=front;
    while(temp!=NULL)                        display C
    {
        cout<<temp->data<<" ";
        temp=temp->next;                          temp
                                 front             rear
    }
                                 A       B        C
}
Search Method
void search(int x)
{
   int a=0;
   node * temp=front;
   while(temp!=NULL)
   {
        if(temp->data==x)
        {
           cout<<"found at index "<<a;
           break;                              x=C
         }                                     a=0
        else
        {
         temp=temp->next;          front       rear
         a++;
        }                          A       B   C
    }
   if(temp==NULL)
   cout<<“value not found";
}
};
Search Method
void search(int x)
{
   int a=0;
   node * temp=front;
   while(temp!=NULL)
   {
        if(temp->data==x)
        {
           cout<<"found at index "<<a;
           break;                              x=C
         }                                     a=0
        else
        {                          temp
         temp=temp->next;          front       rear
         a++;
        }                          A       B   C
    }
   if(temp==NULL)
   cout<<“value not found";
}
};
Search Method
void search(int x)
{
   int a=0;
   node * temp=front;
   while(temp!=NULL)
   {
        if(temp->data==x)
        {
           cout<<"found at index "<<a;
           break;                                 x=C
         }                                        a=1
        else
        {
                                           temp
         temp=temp->next;          front          rear
         a++;
        }                          A       B      C
    }
   if(temp==NULL)
   cout<<“value not found";
}
};
Search Method
void search(int x)
{
   int a=0;
   node * temp=front;
   while(temp!=NULL)
   {
        if(temp->data==x)
        {
           cout<<"found at index "<<a;
           break;                              x=C
         }                                     a=2
        else
        {                                      temp
         temp=temp->next;          front       rear
         a++;
        }                          A       B   C
    }
   if(temp==NULL)
   cout<<“value not found";
}
};
Search Method
void search(int x)
{
   int a=0;
   node * temp=front;
   while(temp!=NULL)
   {
        if(temp->data==x)
        {
           cout<<"found at index "<<a;
           break;                                x=C
         }                                       a=2
        else
        {                                        temp
         temp=temp->next;          front         rear
         a++;
        }                          A       B    C
    }
                                               found at
   if(temp==NULL)
                                                index 2
   cout<<“value not found";
}
};
Main Method
                                          case 2:
void main()                               y=q.pop();
{clrscr();                                if(y!=NULL)
int n, a, y, z;                           cout<<"nvalue popped is: "<<y;
int e=0;                                  break;
   linearQueue q;                         case 3:
   do                                     q.display();
   {cout<<"npress 1 to push";            break;
   cout<<"npress 2 to pop";              case 4:
   cout<<"npress 3 to display";          cout<<“enter value to search?”;
   cout<<“n press 4 to search”;          cin>>z;
   cout<<"npress 5 to exitn";           q.search(z);
   cin>>n;                                break;
   switch(n)                              case 5:
     {                                    e=1;
   case 1:                                break;
   cout<<"enter a number";                }
   cin>>a;                             } while(e==0);
   q.push(a);                      }
   break;
TIME COMPLEXITY
   Insert
    ◦ Best Case: O(1)
    ◦ Worst Case: O(1)
   Remove
    ◦ Best Case: O(1)
    ◦ Worst Case: O(1)
   Search
    ◦ Best Case: O(1)
    ◦ Worst Case: O(n)
LINK LIST IMPLEMENTATION
   OF CIRCULAR QUEUE
Defining the linked list data
structure:
  struct node
  {
       int data;
       node *next;
  };


                     Data   next

                        node
Class circularQueue

class
  circularQueue
{
 public:
   node *rear;
                      rear
   circularQueue()
   {
       rear=NULL;
   }
Insert Method                rear

void insert(int x)
{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
    else
    {
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Insert Method                rear   ptr

void insert(int x)
{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
    else
    {
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Insert Method                rear   ptr

void insert(int x)                  x

{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
    else
    {
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Insert Method                rear   ptr
                                          Address
void insert(int x)                  x     of itself

{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
    else
    {
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Insert Method                rear
                             ptr
                                 Address
void insert(int x)           x   of itself

{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
    else
    {
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Insert Method
void insert(int x)
{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
    else                     rear                ptr

    {                        A
                                 Address
                                 of itself
                                             x
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Insert Method
void insert(int x)
{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
    else                     rear                ptr

    {                        A
                                 Address
                                 of itself
                                             x
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Insert Method
void insert(int x)
{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
    else                     rear       ptr

    {                        A      x
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Insert Method
void insert(int x)
{
  node * ptr = new node;
  ptr -> data=x;
  if(rear==NULL)
     ptr -> next=ptr;
                                 rear
    else                          ptr

    {                        A   x
     ptr->next=rear->next;
     rear->next=ptr;
    }
    rear=ptr;
}
Remove
     Method
int remove()
{
    if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;                       rear
    }
    else                                A   Address
                                            of itself

    {
        int temp=rear->next->data;
        node* ptr=rear->next;
        if(rear==rear->next)
        { rear=NULL;
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)                              temp=A
    {
        cout<<"nlist emptyn";
        return 0;                       rear
    }
    else                                A   Address
                                            of itself

    {
        int temp=rear->next->data;
        node* ptr=rear->next;
        if(rear==rear->next)
        { rear=NULL;
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)                              temp=A
    {
        cout<<"nlist emptyn";          ptr
        return 0;                       rear
    }
    else                                A   Address
                                            of itself

    {
        int temp=rear->next->data;
        node* ptr=rear->next;
        if(rear==rear->next)
        { rear=NULL;
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)                              temp=A
    {
        cout<<"nlist emptyn";         ptr
        return 0;
    }
    else                                A   Address
                                            of itself

    {
        int temp=rear->next->data;
        node* ptr=rear->next;           rear
        if(rear==rear->next)
        { rear=NULL;
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)                              temp=A
    {
        cout<<"nlist emptyn";         ptr
        return 0;
    }
    else                                A   Address
                                            of itself

    {
        int temp=rear->next->data;
        node* ptr=rear->next;           rear
        if(rear==rear->next)
        { rear=NULL;
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;
    }
    else
    {
        int temp=rear->next->data;
        node* ptr=rear->next;                   rear
        if(rear==rear->next)
        { rear=NULL;                    A   B   C
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;
    }
    else
                                        temp=A
    {
        int temp=rear->next->data;
        node* ptr=rear->next;                        rear
        if(rear==rear->next)
        { rear=NULL;                    A        B   C
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;
    }
    else
                                        temp=A
    {
        int temp=rear->next->data;
        node* ptr=rear->next;               ptr       rear
        if(rear==rear->next)
        { rear=NULL;                    A         B   C
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;
    }
    else
                                        temp=A
    {
        int temp=rear->next->data;
        node* ptr=rear->next;               ptr       rear
        if(rear==rear->next)
        { rear=NULL;                    A         B   C
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Remove
     Method
int remove()
{
    if(rear==NULL)
    {
        cout<<"nlist emptyn";
        return 0;
    }
    else
                                        temp=A
    {
        int temp=rear->next->data;
        node* ptr=rear->next;               ptr       rear
        if(rear==rear->next)
        { rear=NULL;                    A         B   C
        }
        else
        {rear->next=rear->next->next;
        }
        delete ptr;
        return temp;
    }
}
Display Method
void display()
{
        if(rear==NULL)
        {
          cout<<"nlist emptyn";
          return;
        }
        node * temp=rear->next;
        do
        {
          cout<<temp->data<<" ";
          temp=temp->next;
        }while(temp!=rear->next);           rear
    }
                                    A   B   C
.
Display Method
void display()
{
        if(rear==NULL)
        {
          cout<<"nlist emptyn";
          return;
        }
        node * temp=rear->next;
        do
        {
          cout<<temp->data<<" ";
          temp=temp->next;
        }while(temp!=rear->next);
                                    temp       rear
    }
.                                   A      B   C
Display Method
void display()
{
        if(rear==NULL)
        {
          cout<<"nlist emptyn";
          return;
        }
        node * temp=rear->next;
        do
        {                                      display A
          cout<<temp->data<<" ";
          temp=temp->next;
        }while(temp!=rear->next);
                                    temp             rear
    }
.                                   A      B         C
Display Method
void display()
{
        if(rear==NULL)
        {
          cout<<"nlist emptyn";
          return;
        }
        node * temp=rear->next;
        do
        {
          cout<<temp->data<<" ";
          temp=temp->next;
        }while(temp!=rear->next);       temp   rear
    }
                                    A   B      C
.
Display Method
void display()
{
        if(rear==NULL)
        {
          cout<<"nlist emptyn";
          return;
        }
        node * temp=rear->next;
        do
        {                                      display B
          cout<<temp->data<<" ";
          temp=temp->next;
        }while(temp!=rear->next);       temp         rear
    }
                                    A   B           C
.
Display Method
void display()
{
        if(rear==NULL)
        {
          cout<<"nlist emptyn";
          return;
        }
        node * temp=rear->next;
        do
        {
          cout<<temp->data<<" ";
          temp=temp->next;                   temp
        }while(temp!=rear->next);           rear
    }
                                    A   B   C
.
Display Method
void display()
{
        if(rear==NULL)
        {
          cout<<"nlist emptyn";
          return;
        }
        node * temp=rear->next;
        do
        {                                   display C
          cout<<temp->data<<" ";
          temp=temp->next;                         temp
        }while(temp!=rear->next);                 rear
    }
                                    A   B        C
.
Search Method
void search(int x)
{
  int a=0;
  node * temp= rear->next
  while(temp!=NULL)
  {
       if(temp->data==x)
       {
          cout<<"found at index "<<a;
          break;                            x=C
        }                                   a=0
       else
       {
        temp=temp->next;
        a++;                                rear
       }                                    C
   }                              A     B
  if(temp==NULL)
  cout<<“value not found";
}
};
Search Method
void search(int x)
{
  int a=0;
  node * temp=rear->next;
  while(temp!=NULL)
  {
       if(temp->data==x)
       {
          cout<<"found at index "<<a;
          break;                             x=C
        }                                    a=0
       else
       {
        temp=temp->next;          temp
        a++;                                 rear
       }                                     C
   }                              A      B
  if(temp==NULL)
  cout<<“value not found";
}
};
Search Method
void search(int x)
{
  int a=0;
  node * temp=rear->next;
  while(temp!=NULL)
  {
       if(temp->data==x)
       {
          cout<<"found at index "<<a;
          break;                                   x=C
        }                                          a=1
       else
       {
        temp=temp->next;                    temp
        a++;                                       rear
       }                                           C
   }                              A     B
  if(temp==NULL)
  cout<<“value not found";
}
};
Search Method
void search(int x)
{
  int a=0;
  node * temp=rear->next;
  while(temp!=NULL)
  {
       if(temp->data==x)
       {
          cout<<"found at index "<<a;
          break;                            x=C
        }                                   a=2
       else
       {
        temp=temp->next;                    temp
        a++;                                 rear
       }                                    C
   }                              A     B
  if(temp==NULL)
  cout<<“value not found";
}
};
Search Method
void search(int x)
{
  int a=0;
  node * temp=rear->next;
  while(temp!=NULL)
  {
       if(temp->data==x)
       {
          cout<<"found at index "<<a;
          break;                              x=C
        }                                     a=2
       else
       {
        temp=temp->next;                     temp
        a++;                                  rear
       }                                     C
   }                              A     B
                                            found at
  if(temp==NULL)
                                             index 2
  cout<<“value not found";
}
};
Main Method
                                          case 2:
void main()                               y=q.pop();
{clrscr();                                if(y!=NULL)
int n, a, y, z;                           cout<<"nvalue popped is: "<<y;
int e=0;                                  break;
   circularQueue q;                       case 3:
   do                                     q.display();
   {cout<<"npress 1 to push";            break;
   cout<<"npress 2 to pop";              case 4:
   cout<<"npress 3 to display";          cout<<“enter value to search?”;
   cout<<“n press 4 to search”;          cin>>z;
   cout<<"npress 5 to exitn";           q.search(z);
   cin>>n;                                break;
   switch(n)                              case 5:
    {                                     e=1;
   case 1:                                break;
   cout<<"enter a number";                }
   cin>>a;                             } while(e==0);
   q.push(a);                      }
   break;
TIME COMPLEXITY
   Insert
    ◦ Best Case: O(1)
    ◦ Worst Case: O(1)
   Remove
    ◦ Best Case: O(1)
    ◦ Worst Case: O(1)
   Search
    ◦ Best Case: O(1)
    ◦ Worst Case: O(n)
THANK YOU!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Linked list
Linked listLinked list
Linked list
 
Single linked list
Single linked listSingle linked list
Single linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Linked list
Linked listLinked list
Linked list
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Linked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory AllocationLinked List Static and Dynamic Memory Allocation
Linked List Static and Dynamic Memory Allocation
 
11 15 (doubly linked list)
11 15 (doubly linked list)11 15 (doubly linked list)
11 15 (doubly linked list)
 
CSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsCSE240 Doubly Linked Lists
CSE240 Doubly Linked Lists
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)Data Structure (Dynamic Array and Linked List)
Data Structure (Dynamic Array and Linked List)
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
linked list using c
linked list using clinked list using c
linked list using c
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 

Destacado

Linked List data structure
Linked List data structureLinked List data structure
Linked List data structureMarcus Biel
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)shah alom
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structureTushar Aneyrao
 
agi software solutions
agi software solutionsagi software solutions
agi software solutionssrilakshmi491
 
【schoo WEB-campus】「頭を使う」ってどういうことだろう? 先生:細谷 功
【schoo WEB-campus】「頭を使う」ってどういうことだろう? 先生:細谷 功【schoo WEB-campus】「頭を使う」ってどういうことだろう? 先生:細谷 功
【schoo WEB-campus】「頭を使う」ってどういうことだろう? 先生:細谷 功schoowebcampus
 
2015 Toyota Avalon | Wilkes-Barre Area Toyota Dealer
2015 Toyota Avalon | Wilkes-Barre Area Toyota Dealer2015 Toyota Avalon | Wilkes-Barre Area Toyota Dealer
2015 Toyota Avalon | Wilkes-Barre Area Toyota Dealerscranton toyota
 
Learning tutorials-Leading providers for home tuitions
Learning tutorials-Leading providers for home tuitionsLearning tutorials-Leading providers for home tuitions
Learning tutorials-Leading providers for home tuitionslearningtutorials123
 
Letting go of past hurts and moving forward
Letting go of past hurts and moving forwardLetting go of past hurts and moving forward
Letting go of past hurts and moving forwardExcelr8 Soul Emergence
 
2014 Call Center World Moscow relocation business case
2014 Call Center World Moscow relocation business case2014 Call Center World Moscow relocation business case
2014 Call Center World Moscow relocation business caseDennis Lyubyvy
 
Print connecté pour booster ses ventes
Print connecté pour booster ses ventesPrint connecté pour booster ses ventes
Print connecté pour booster ses ventesarvato France
 

Destacado (20)

Linked List data structure
Linked List data structureLinked List data structure
Linked List data structure
 
Link List
Link ListLink List
Link List
 
Linked list
Linked listLinked list
Linked list
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)
 
Linked list
Linked listLinked list
Linked list
 
Array implementation and linked list as datat structure
Array implementation and linked list as datat structureArray implementation and linked list as datat structure
Array implementation and linked list as datat structure
 
linked list
linked list linked list
linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Georgia's location
Georgia's locationGeorgia's location
Georgia's location
 
agi software solutions
agi software solutionsagi software solutions
agi software solutions
 
【schoo WEB-campus】「頭を使う」ってどういうことだろう? 先生:細谷 功
【schoo WEB-campus】「頭を使う」ってどういうことだろう? 先生:細谷 功【schoo WEB-campus】「頭を使う」ってどういうことだろう? 先生:細谷 功
【schoo WEB-campus】「頭を使う」ってどういうことだろう? 先生:細谷 功
 
2kkkk-24 (1)
2kkkk-24 (1)2kkkk-24 (1)
2kkkk-24 (1)
 
2015 Toyota Avalon | Wilkes-Barre Area Toyota Dealer
2015 Toyota Avalon | Wilkes-Barre Area Toyota Dealer2015 Toyota Avalon | Wilkes-Barre Area Toyota Dealer
2015 Toyota Avalon | Wilkes-Barre Area Toyota Dealer
 
Learning tutorials-Leading providers for home tuitions
Learning tutorials-Leading providers for home tuitionsLearning tutorials-Leading providers for home tuitions
Learning tutorials-Leading providers for home tuitions
 
Boots
Boots Boots
Boots
 
Cloud
CloudCloud
Cloud
 
Letting go of past hurts and moving forward
Letting go of past hurts and moving forwardLetting go of past hurts and moving forward
Letting go of past hurts and moving forward
 
2014 Call Center World Moscow relocation business case
2014 Call Center World Moscow relocation business case2014 Call Center World Moscow relocation business case
2014 Call Center World Moscow relocation business case
 
Print connecté pour booster ses ventes
Print connecté pour booster ses ventesPrint connecté pour booster ses ventes
Print connecté pour booster ses ventes
 

Similar a Link list

Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxnoreendchesterton753
 
Write code in c++ Program to a topological sort on a graph Program pl.docx
Write code in c++ Program to a topological sort on a graph  Program pl.docxWrite code in c++ Program to a topological sort on a graph  Program pl.docx
Write code in c++ Program to a topological sort on a graph Program pl.docxnoreendchesterton753
 
Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxkarlynwih
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfflashfashioncasualwe
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklistilsamaryum
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxMeghaKulkarni27
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfarorastores
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresLakshmi Sarvani Videla
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignmentsreekanth3dce
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfAnkitchhabra28
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfconnellalykshamesb60
 
Swapping ball - Nguyễn Đình Nhật - Nguyễn Như Hải Triều
Swapping ball - Nguyễn Đình Nhật - Nguyễn Như Hải TriềuSwapping ball - Nguyễn Đình Nhật - Nguyễn Như Hải Triều
Swapping ball - Nguyễn Đình Nhật - Nguyễn Như Hải Triềumrcoffee282
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdffantoosh1
 
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfgalagirishp
 

Similar a Link list (20)

Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docx
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 
Write code in c++ Program to a topological sort on a graph Program pl.docx
Write code in c++ Program to a topological sort on a graph  Program pl.docxWrite code in c++ Program to a topological sort on a graph  Program pl.docx
Write code in c++ Program to a topological sort on a graph Program pl.docx
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
 
Write code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docxWrite code in C++ Write a program to perform a topological sort on a g.docx
Write code in C++ Write a program to perform a topological sort on a g.docx
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
U2.linked list
U2.linked listU2.linked list
U2.linked list
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
 
Note             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdfNote             Given Code modified as required and required met.pdf
Note             Given Code modified as required and required met.pdf
 
Using the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdfUsing the provided table interface table.h and the sample linked lis.pdf
Using the provided table interface table.h and the sample linked lis.pdf
 
Swapping ball - Nguyễn Đình Nhật - Nguyễn Như Hải Triều
Swapping ball - Nguyễn Đình Nhật - Nguyễn Như Hải TriềuSwapping ball - Nguyễn Đình Nhật - Nguyễn Như Hải Triều
Swapping ball - Nguyễn Đình Nhật - Nguyễn Như Hải Triều
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
 

Más de Syeda Javeria

تعلق باللہ Relationship with Allah
تعلق باللہ  Relationship with Allahتعلق باللہ  Relationship with Allah
تعلق باللہ Relationship with AllahSyeda Javeria
 
Social Media - Introduction, Importance and our Responsibility to spread Islam
Social Media - Introduction, Importance and our Responsibility to spread IslamSocial Media - Introduction, Importance and our Responsibility to spread Islam
Social Media - Introduction, Importance and our Responsibility to spread IslamSyeda Javeria
 
Management by Objectives
Management by ObjectivesManagement by Objectives
Management by ObjectivesSyeda Javeria
 
Patient record management system(s.e. diagrams)
Patient record management system(s.e. diagrams)Patient record management system(s.e. diagrams)
Patient record management system(s.e. diagrams)Syeda Javeria
 
Nabi s.a.w.w ki daawat e deen
Nabi s.a.w.w ki daawat e deenNabi s.a.w.w ki daawat e deen
Nabi s.a.w.w ki daawat e deenSyeda Javeria
 
Windows Movie Maker Tutorial
Windows Movie Maker TutorialWindows Movie Maker Tutorial
Windows Movie Maker TutorialSyeda Javeria
 
Direct and Online marketing
Direct and Online marketingDirect and Online marketing
Direct and Online marketingSyeda Javeria
 
TRANSFORMATION OF AFFIRMATIVE SENTENCES
TRANSFORMATION OF AFFIRMATIVE SENTENCESTRANSFORMATION OF AFFIRMATIVE SENTENCES
TRANSFORMATION OF AFFIRMATIVE SENTENCESSyeda Javeria
 

Más de Syeda Javeria (15)

تعلق باللہ Relationship with Allah
تعلق باللہ  Relationship with Allahتعلق باللہ  Relationship with Allah
تعلق باللہ Relationship with Allah
 
Whatsapp
Whatsapp Whatsapp
Whatsapp
 
Haya aur Iman
Haya aur ImanHaya aur Iman
Haya aur Iman
 
Social Media - Introduction, Importance and our Responsibility to spread Islam
Social Media - Introduction, Importance and our Responsibility to spread IslamSocial Media - Introduction, Importance and our Responsibility to spread Islam
Social Media - Introduction, Importance and our Responsibility to spread Islam
 
Phishing
PhishingPhishing
Phishing
 
Management by Objectives
Management by ObjectivesManagement by Objectives
Management by Objectives
 
Patient record management system(s.e. diagrams)
Patient record management system(s.e. diagrams)Patient record management system(s.e. diagrams)
Patient record management system(s.e. diagrams)
 
Hazrat ibrahim a.s.
Hazrat ibrahim a.s.Hazrat ibrahim a.s.
Hazrat ibrahim a.s.
 
Nabi s.a.w.w ki daawat e deen
Nabi s.a.w.w ki daawat e deenNabi s.a.w.w ki daawat e deen
Nabi s.a.w.w ki daawat e deen
 
Depreciation
DepreciationDepreciation
Depreciation
 
Squid
SquidSquid
Squid
 
Windows Movie Maker Tutorial
Windows Movie Maker TutorialWindows Movie Maker Tutorial
Windows Movie Maker Tutorial
 
Direct and Online marketing
Direct and Online marketingDirect and Online marketing
Direct and Online marketing
 
Branding
BrandingBranding
Branding
 
TRANSFORMATION OF AFFIRMATIVE SENTENCES
TRANSFORMATION OF AFFIRMATIVE SENTENCESTRANSFORMATION OF AFFIRMATIVE SENTENCES
TRANSFORMATION OF AFFIRMATIVE SENTENCES
 

Último

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Último (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Link list

  • 1.
  • 2. LINKED LIST PRESENTED BY: Javeria (11-arid-3303) MIT-3 University Institute of Information Technology, Rawalpindi (UIIT, UAAR)
  • 3. INTRODUTION  Link List is an ordered collection of elements called nodes. The nodes are connected by pointer.  Each node has two parts 1) Data Field – Stores data of the node. Same data type 2) Link Field – Store address of the next node ( i.e. Link to the next node) NEXT NODE : DATA
  • 4. ARRAY VS. LINK LIST Aspect Array Link List Size  Fixed size.  Grow and contract according to insertions and deletions. Storage  Static: It’s location is  Dynamic: It’s node is capacity allocated during compile located during run time. time. Accessing the  Direct or random access  Sequential access element method. method.  Specify the array index or  Traverse starting from the subscript. first node in the list by pointer. 4
  • 5. SINGLY LINK LIST IMPLEMENTATION IN STACKS: A B C top IMPLEMENTATION IN LINEAR QUEUE: front A B C rear IMPLEMENTATION IN CIRCULAR QUEUE: A B C rear DOUBLY LINK LIST A B C rear
  • 6. LINKED LIST IMPLEMENTATION  Stacks  Linear Queue  Circular Queue
  • 7. Functions ◦ We will discuss the following functions in above three data structures:  Insertion  Deletion  Display  Search
  • 9. Defining the linked list data structure: struct node { int data; node *next; }; Data next node
  • 10. STACK CLASS class stack { public: node * top; stack( ) { top top=NULL; }
  • 11. Push method void push(int x) { node * ptr=new node; top ptr->data=x; ptr->next=top; top=ptr; }
  • 12. Push method void push(int x) ptr { node * ptr=new node; top ptr->data=x; ptr->next=top; top=ptr; }
  • 13. Push method void push(int x) ptr { x node * ptr=new node; top ptr->data=x; ptr->next=top; top=ptr; }
  • 14. Push method void push(int x) ptr { x node * ptr=new node; top ptr->data=x; ptr->next=top; top=ptr; }
  • 15. Push method void push(int x) ptr { x node * ptr=new node; top ptr->data=x; ptr->next=top; top=ptr; }
  • 16. Push method void push(int x) { top ptr node * ptr=new node; ptr->data=x; x ptr->next=top; top=ptr; }
  • 17. - All nodes are connected to each other through pointers - Link of the first node is NULL pointer denoted by X - Null pointer indicates the start of the stack list top D C B A
  • 18. Pop Method int pop() { top if(top==NULL) { cout<<"nlist emptyn"; D return; } C else { int temp=top->data; node* ptr=top; B top=top->next; delete ptr; return temp; A } }
  • 19. Pop Method int pop() { top temp=D if(top==NULL) { cout<<"nlist emptyn"; D return ; } C else { int temp=top->data; node* ptr=top; B top=top->next; delete ptr; return temp; A } }
  • 20. Pop Method int pop() ptr { top temp=D if(top==NULL) { cout<<"nlist emptyn"; D return ; } C else { int temp=top->data; node* ptr=top; B top=top->next; delete ptr; return temp; A } }
  • 21. Pop Method int pop() { ptr temp=D if(top==NULL) { D cout<<"nlist emptyn"; return ; top } C else { int temp=top->data; node* ptr=top; B top=top->next; delete ptr; return temp; A } }
  • 22. Pop Method int pop() { ptr temp=D if(top==NULL) { D cout<<"nlist emptyn"; return ; top } C else { int temp=top->data; node* ptr=top; B top=top->next; delete ptr; return temp; A } }
  • 23. Display Method void display() { node * temp; top temp=top; if(top==NULL) D { cout<<"stack empty"; return; C } while(temp!=NULL) { B cout<<temp->data<<" "; temp=temp->next; } A }
  • 24. Display Method void display() { node * temp; tem top p temp=top; if(top==NULL) D { cout<<"stack empty"; return; C } while(temp!=NULL) { B cout<<temp->data<<" "; temp=temp->next; } A }
  • 25. Display Method void display() { node * temp; tem top p temp=top; display D if(top==NULL) D { cout<<"stack empty"; return; C } while(temp!=NULL) { B cout<<temp->data<<" "; temp=temp->next; } A }
  • 26. Display Method void display() { node * temp; top temp=top; if(top==NULL) D { cout<<"stack empty"; tem p return; C } while(temp!=NULL) { B cout<<temp->data<<" "; temp=temp->next; } A }
  • 27. Display Method void display() { node * temp; top temp=top; if(top==NULL) D { cout<<"stack empty"; tem p return; C display C } while(temp!=NULL) { B cout<<temp->data<<" "; temp=temp->next; } A }
  • 28. Display Method void display() { node * temp; top temp=top; if(top==NULL) D { cout<<"stack empty"; return; C } tem while(temp!=NULL) p { B cout<<temp->data<<" "; temp=temp->next; } A }
  • 29. Display Method void display() { node * temp; top temp=top; if(top==NULL) D { cout<<"stack empty"; return; C } tem while(temp!=NULL) p display B { B cout<<temp->data<<" "; temp=temp->next; } A }
  • 30. Display Method void display() { node * temp; top temp=top; if(top==NULL) D { cout<<"stack empty"; return; C } while(temp!=NULL) { B cout<<temp->data<<" "; tem temp=temp->next; p } A }
  • 31. Display Method void display() { node * temp; top temp=top; if(top==NULL) D { cout<<"stack empty"; return; C } while(temp!=NULL) { B cout<<temp->data<<" "; tem temp=temp->next; p display A } A }
  • 32. Display Method void display() { node * temp; top temp=top; if(top==NULL) D { cout<<"stack empty"; return; C } while(temp!=NULL) { B cout<<temp->data<<" "; temp=temp->next; } A } temp = NULL
  • 33. Search Method void search(int x) { int a=0; //index calculated from top node * temp=top; x=B while(temp!=NULL) a=0 { top if(temp->data==x) { D cout<<"found at index "<<a; break; } else C { temp=temp->next; a++; B } } if(temp==NULL) cout<<“value not found"; A } };
  • 34. Search Method void search(int x) { int a=0; //index calculated from top node * temp=top; x=B while(temp!=NULL) tem a=0 { top p if(temp->data==x) { D cout<<"found at index "<<a; break; } else C { temp=temp->next; a++; B } } if(temp==NULL) cout<<“value not found"; A } };
  • 35. Search Method void search(int x) { int a=0; //index calculated from top node * temp=top; x=B while(temp!=NULL) a=1 { top if(temp->data==x) { D cout<<"found at index "<<a; break; tem } p else C { temp=temp->next; a++; B } } if(temp==NULL) cout<<“value not found"; A } };
  • 36. Search Method void search(int x) { int a=0; //index calculated from top node * temp=top; x=B while(temp!=NULL) a=2 { top if(temp->data==x) { D cout<<"found at index "<<a; break; } else C { tem temp=temp->next; p a++; B } } if(temp==NULL) cout<<“value not found"; A } };
  • 37. Search Method void search(int x) { int a=0; //index calculated from top node * temp=top; x=B while(temp!=NULL) a=2 { top if(temp->data==x) { D cout<<"found at index "<<a; break; } else C { tem temp=temp->next; p a++; found at B } index 2 } if(temp==NULL) cout<<“value not found"; A } };
  • 38. Main Method case 2: void main() y=s.pop(); {clrscr(); if(y!=NULL) int n, a, y, z; cout<<"nvalue popped is: "<<y; int e=0; break; stack s; case 3: do s.display(); {cout<<"npress 1 to push"; break; cout<<"npress 2 to pop"; case 4: cout<<"npress 3 to display"; cout<<“enter value to search?”; cout<<“n press 4 to search”; cin>>z; cout<<"npress 5to exitn"; s.search(z); cin>>n; break; switch(n) case 5: { e=1; case 1: break; cout<<"enter a number"; } cin>>a; } while(e==0); s.push(a); } break;
  • 39. TIME COMPLEXITY “Time Complexity is a measure of the amount of time required to execute an algorithm.”  Push ◦ Best Case: O(1) ◦ Worst Case: O(1)  Pop ◦ Best Case: O(1) ◦ Worst Case: O(1)  Search ◦ Best Case: O(1) ◦ Worst Case: O(n)
  • 41. Defining the linked list data structure: struct node { int data; node *next; }; Data next node
  • 42. Class Linear Queue class linearQueue { public: node *rear; node *front; linearQueue() rear { front rear=NULL; front=NULL; }
  • 43. Insert Method void insert(int x) rear front { node * ptr=new node; ptr->data=x; if(rear==NULL) { front=ptr; } else { rear->next=ptr; } ptr->next=NULL; rear=ptr; }
  • 44. Insert Method void insert(int x) rear front ptr { node * ptr=new node; ptr->data=x; if(rear==NULL) { front=ptr; } else { rear->next=ptr; } ptr->next=NULL; rear=ptr; }
  • 45. Insert Method void insert(int x) rear front ptr { node * ptr=new x node; ptr->data=x; if(rear==NULL) { front=ptr; } else { rear->next=ptr; } ptr->next=NULL; rear=ptr; }
  • 46. Insert Method void insert(int x) rear front ptr { node * ptr=new x node; ptr->data=x; if(rear==NULL) { front=ptr; } else { rear->next=ptr; } ptr->next=NULL; rear=ptr; }
  • 47. Insert Method void insert(int x) rear front ptr { node * ptr=new x node; ptr->data=x; if(rear==NULL) { front=ptr; } else { rear->next=ptr; } ptr->next=NULL; rear=ptr; }
  • 48. Insert Method rear void insert(int x) front { ptr node * ptr=new x node; ptr->data=x; if(rear==NULL) { front=ptr; } else { rear->next=ptr; } ptr->next=NULL; rear=ptr; }
  • 49. Insert Method void insert(int x) { node * ptr=new node; ptr->data=x; if(rear==NULL) { front=ptr; } else rear { front ptr rear->next=ptr; } A ptr x ptr->next=NULL; rear=ptr; }
  • 50. Insert Method void insert(int x) { node * ptr=new node; ptr->data=x; if(rear==NULL) { front=ptr; } else rear { front ptr rear->next=ptr; } A x ptr->next=NULL; rear=ptr; }
  • 51. Insert Method void insert(int x) { node * ptr=new node; ptr->data=x; if(rear==NULL) { front=ptr; } else rear { front ptr rear->next=ptr; } A ptr x ptr->next=NULL; rear=ptr; }
  • 52. Insert Method void insert(int x) { node * ptr=new node; ptr->data=x; if(rear==NULL) { front=ptr; } else rear { front ptr rear->next=ptr; } A ptr x ptr->next=NULL; rear=ptr; }
  • 53. Remove Method int remove() { if(rear==NULL) { rear temp= A front cout<<"nlist emptyn"; return 0; A } else { int temp=front->data; node* ptr=front; if(front->next==NULL) { rear=NULL; } else { front=ptr->next; } delete ptr; return temp; } }
  • 54. Remove Method int remove() temp= A { if(rear==NULL) ptr { rear front cout<<"nlist emptyn"; return 0; A } else { int temp=front->data; node* ptr=front; if(front->next==NULL) { rear=NULL; } else { front=ptr->next; } delete ptr; return temp; } }
  • 55. Remove Method int remove() temp= A { if(rear==NULL) ptr { front rear cout<<"nlist emptyn"; return 0; A } else { int temp=front->data; node* ptr=front; if(front->next==NULL) { rear=NULL; } else { front=ptr->next; } delete ptr; return temp; } }
  • 56. Remove Method int remove() temp= A { if(rear==NULL) ptr { front rear cout<<"nlist emptyn"; return 0; A } else { int temp=front->data; node* ptr=front; if(front->next==NULL) { rear=NULL; } else { front=ptr->next; } delete ptr; return temp; } }
  • 57. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; } else { int temp=front->data; temp=A node* ptr=front; if(front->next==NULL) ptr { rear=NULL; } front rear else A B { front=ptr->next; } delete ptr; return temp; } }
  • 58. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; } else { int temp=front->data; temp=A node* ptr=front; if(front->next==NULL) front ptr { rear=NULL; } rear else A B { front=ptr->next; } delete ptr; return temp; } }
  • 59. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; } else { int temp=front->data; temp=A node* ptr=front; if(front->next==NULL) front ptr { rear=NULL; } rear else A B { front=ptr->next; } delete ptr; return temp; } }
  • 60. Display Method void display() { if(rear==NULL) { cout<<"list empty"; return; } cout<<"data in nodes of link list:t"; node *temp=front; while(temp!=NULL) { cout<<temp->data<<" "; temp=temp->next; front rear } A B C }
  • 61. Display Method void display() { if(rear==NULL) { cout<<"list empty"; return; } cout<<"data in nodes of link list:t"; node *temp=front; while(temp!=NULL) { cout<<temp->data<<" "; temp=temp->next; temp front rear } A B C }
  • 62. Display Method void display() { if(rear==NULL) { cout<<"list empty"; return; } cout<<"data in nodes of link list:t"; node *temp=front; while(temp!=NULL) display A { cout<<temp->data<<" "; temp=temp->next; temp front rear } A B C }
  • 63. Display Method void display() { if(rear==NULL) { cout<<"list empty"; return; } cout<<"data in nodes of link list:t"; node *temp=front; while(temp!=NULL) { cout<<temp->data<<" "; temp=temp->next; temp front rear } A B C }
  • 64. Display Method void display() { if(rear==NULL) { cout<<"list empty"; return; } cout<<"data in nodes of link list:t"; node *temp=front; while(temp!=NULL) display B { cout<<temp->data<<" "; temp=temp->next; temp front rear } A B C }
  • 65. Display Method void display() { if(rear==NULL) { cout<<"list empty"; return; } cout<<"data in nodes of link list:t"; node *temp=front; while(temp!=NULL) { cout<<temp->data<<" "; temp=temp->next; temp front rear } A B C }
  • 66. Display Method void display() { if(rear==NULL) { cout<<"list empty"; return; } cout<<"data in nodes of link list:t"; node *temp=front; while(temp!=NULL) display C { cout<<temp->data<<" "; temp=temp->next; temp front rear } A B C }
  • 67. Search Method void search(int x) { int a=0; node * temp=front; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=0 else { temp=temp->next; front rear a++; } A B C } if(temp==NULL) cout<<“value not found"; } };
  • 68. Search Method void search(int x) { int a=0; node * temp=front; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=0 else { temp temp=temp->next; front rear a++; } A B C } if(temp==NULL) cout<<“value not found"; } };
  • 69. Search Method void search(int x) { int a=0; node * temp=front; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=1 else { temp temp=temp->next; front rear a++; } A B C } if(temp==NULL) cout<<“value not found"; } };
  • 70. Search Method void search(int x) { int a=0; node * temp=front; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=2 else { temp temp=temp->next; front rear a++; } A B C } if(temp==NULL) cout<<“value not found"; } };
  • 71. Search Method void search(int x) { int a=0; node * temp=front; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=2 else { temp temp=temp->next; front rear a++; } A B C } found at if(temp==NULL) index 2 cout<<“value not found"; } };
  • 72. Main Method case 2: void main() y=q.pop(); {clrscr(); if(y!=NULL) int n, a, y, z; cout<<"nvalue popped is: "<<y; int e=0; break; linearQueue q; case 3: do q.display(); {cout<<"npress 1 to push"; break; cout<<"npress 2 to pop"; case 4: cout<<"npress 3 to display"; cout<<“enter value to search?”; cout<<“n press 4 to search”; cin>>z; cout<<"npress 5 to exitn"; q.search(z); cin>>n; break; switch(n) case 5: { e=1; case 1: break; cout<<"enter a number"; } cin>>a; } while(e==0); q.push(a); } break;
  • 73. TIME COMPLEXITY  Insert ◦ Best Case: O(1) ◦ Worst Case: O(1)  Remove ◦ Best Case: O(1) ◦ Worst Case: O(1)  Search ◦ Best Case: O(1) ◦ Worst Case: O(n)
  • 74. LINK LIST IMPLEMENTATION OF CIRCULAR QUEUE
  • 75. Defining the linked list data structure: struct node { int data; node *next; }; Data next node
  • 76. Class circularQueue class circularQueue { public: node *rear; rear circularQueue() { rear=NULL; }
  • 77. Insert Method rear void insert(int x) { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; else { ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 78. Insert Method rear ptr void insert(int x) { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; else { ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 79. Insert Method rear ptr void insert(int x) x { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; else { ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 80. Insert Method rear ptr Address void insert(int x) x of itself { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; else { ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 81. Insert Method rear ptr Address void insert(int x) x of itself { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; else { ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 82. Insert Method void insert(int x) { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; else rear ptr { A Address of itself x ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 83. Insert Method void insert(int x) { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; else rear ptr { A Address of itself x ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 84. Insert Method void insert(int x) { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; else rear ptr { A x ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 85. Insert Method void insert(int x) { node * ptr = new node; ptr -> data=x; if(rear==NULL) ptr -> next=ptr; rear else ptr { A x ptr->next=rear->next; rear->next=ptr; } rear=ptr; }
  • 86. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; rear } else A Address of itself { int temp=rear->next->data; node* ptr=rear->next; if(rear==rear->next) { rear=NULL; } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 87. Remove Method int remove() { if(rear==NULL) temp=A { cout<<"nlist emptyn"; return 0; rear } else A Address of itself { int temp=rear->next->data; node* ptr=rear->next; if(rear==rear->next) { rear=NULL; } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 88. Remove Method int remove() { if(rear==NULL) temp=A { cout<<"nlist emptyn"; ptr return 0; rear } else A Address of itself { int temp=rear->next->data; node* ptr=rear->next; if(rear==rear->next) { rear=NULL; } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 89. Remove Method int remove() { if(rear==NULL) temp=A { cout<<"nlist emptyn"; ptr return 0; } else A Address of itself { int temp=rear->next->data; node* ptr=rear->next; rear if(rear==rear->next) { rear=NULL; } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 90. Remove Method int remove() { if(rear==NULL) temp=A { cout<<"nlist emptyn"; ptr return 0; } else A Address of itself { int temp=rear->next->data; node* ptr=rear->next; rear if(rear==rear->next) { rear=NULL; } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 91. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; } else { int temp=rear->next->data; node* ptr=rear->next; rear if(rear==rear->next) { rear=NULL; A B C } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 92. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; } else temp=A { int temp=rear->next->data; node* ptr=rear->next; rear if(rear==rear->next) { rear=NULL; A B C } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 93. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; } else temp=A { int temp=rear->next->data; node* ptr=rear->next; ptr rear if(rear==rear->next) { rear=NULL; A B C } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 94. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; } else temp=A { int temp=rear->next->data; node* ptr=rear->next; ptr rear if(rear==rear->next) { rear=NULL; A B C } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 95. Remove Method int remove() { if(rear==NULL) { cout<<"nlist emptyn"; return 0; } else temp=A { int temp=rear->next->data; node* ptr=rear->next; ptr rear if(rear==rear->next) { rear=NULL; A B C } else {rear->next=rear->next->next; } delete ptr; return temp; } }
  • 96. Display Method void display() { if(rear==NULL) { cout<<"nlist emptyn"; return; } node * temp=rear->next; do { cout<<temp->data<<" "; temp=temp->next; }while(temp!=rear->next); rear } A B C .
  • 97. Display Method void display() { if(rear==NULL) { cout<<"nlist emptyn"; return; } node * temp=rear->next; do { cout<<temp->data<<" "; temp=temp->next; }while(temp!=rear->next); temp rear } . A B C
  • 98. Display Method void display() { if(rear==NULL) { cout<<"nlist emptyn"; return; } node * temp=rear->next; do { display A cout<<temp->data<<" "; temp=temp->next; }while(temp!=rear->next); temp rear } . A B C
  • 99. Display Method void display() { if(rear==NULL) { cout<<"nlist emptyn"; return; } node * temp=rear->next; do { cout<<temp->data<<" "; temp=temp->next; }while(temp!=rear->next); temp rear } A B C .
  • 100. Display Method void display() { if(rear==NULL) { cout<<"nlist emptyn"; return; } node * temp=rear->next; do { display B cout<<temp->data<<" "; temp=temp->next; }while(temp!=rear->next); temp rear } A B C .
  • 101. Display Method void display() { if(rear==NULL) { cout<<"nlist emptyn"; return; } node * temp=rear->next; do { cout<<temp->data<<" "; temp=temp->next; temp }while(temp!=rear->next); rear } A B C .
  • 102. Display Method void display() { if(rear==NULL) { cout<<"nlist emptyn"; return; } node * temp=rear->next; do { display C cout<<temp->data<<" "; temp=temp->next; temp }while(temp!=rear->next); rear } A B C .
  • 103. Search Method void search(int x) { int a=0; node * temp= rear->next while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=0 else { temp=temp->next; a++; rear } C } A B if(temp==NULL) cout<<“value not found"; } };
  • 104. Search Method void search(int x) { int a=0; node * temp=rear->next; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=0 else { temp=temp->next; temp a++; rear } C } A B if(temp==NULL) cout<<“value not found"; } };
  • 105. Search Method void search(int x) { int a=0; node * temp=rear->next; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=1 else { temp=temp->next; temp a++; rear } C } A B if(temp==NULL) cout<<“value not found"; } };
  • 106. Search Method void search(int x) { int a=0; node * temp=rear->next; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=2 else { temp=temp->next; temp a++; rear } C } A B if(temp==NULL) cout<<“value not found"; } };
  • 107. Search Method void search(int x) { int a=0; node * temp=rear->next; while(temp!=NULL) { if(temp->data==x) { cout<<"found at index "<<a; break; x=C } a=2 else { temp=temp->next; temp a++; rear } C } A B found at if(temp==NULL) index 2 cout<<“value not found"; } };
  • 108. Main Method case 2: void main() y=q.pop(); {clrscr(); if(y!=NULL) int n, a, y, z; cout<<"nvalue popped is: "<<y; int e=0; break; circularQueue q; case 3: do q.display(); {cout<<"npress 1 to push"; break; cout<<"npress 2 to pop"; case 4: cout<<"npress 3 to display"; cout<<“enter value to search?”; cout<<“n press 4 to search”; cin>>z; cout<<"npress 5 to exitn"; q.search(z); cin>>n; break; switch(n) case 5: { e=1; case 1: break; cout<<"enter a number"; } cin>>a; } while(e==0); q.push(a); } break;
  • 109. TIME COMPLEXITY  Insert ◦ Best Case: O(1) ◦ Worst Case: O(1)  Remove ◦ Best Case: O(1) ◦ Worst Case: O(1)  Search ◦ Best Case: O(1) ◦ Worst Case: O(n)