SlideShare a Scribd company logo
1 of 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!

More Related Content

What's hot

Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked list
Amit Vats
 

What's hot (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
 

Viewers also liked

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
Tushar Aneyrao
 
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
scranton toyota
 

Viewers also liked (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 to Link list

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
noreendchesterton753
 
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
Malikireddy 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.pdf
flashfashioncasualwe
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
MeghaKulkarni27
 
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
arorastores
 
Datastructures asignment
Datastructures asignmentDatastructures asignment
Datastructures asignment
sreekanth3dce
 
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
Ankitchhabra28
 
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
connellalykshamesb60
 
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
mrcoffee282
 
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
feelinggift
 
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
fantoosh1
 
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
galagirishp
 

Similar to 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
 

More from Syeda Javeria

Direct and Online marketing
Direct and Online marketingDirect and Online marketing
Direct and Online marketing
Syeda Javeria
 
TRANSFORMATION OF AFFIRMATIVE SENTENCES
TRANSFORMATION OF AFFIRMATIVE SENTENCESTRANSFORMATION OF AFFIRMATIVE SENTENCES
TRANSFORMATION OF AFFIRMATIVE SENTENCES
Syeda Javeria
 

More from 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
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

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)