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

Linked list
Linked listLinked list
Linked list
RahulGandhi110
 
Single linked list
Single linked listSingle linked list
Single linked list
jasbirsingh chauhan
 
Linked lists
Linked listsLinked lists
Linked list
Linked listLinked list
Linked list
akshat360
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
Afaq Mansoor Khan
 
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
Prof Ansari
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
Shubham Sharma
 
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)
Adam Mukharil Bachtiar
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
Adam Mukharil Bachtiar
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Katang Isip
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
Muhazzab Chouhadry
 
linked list using c
linked list using clinked list using c
linked list using c
Venkat Reddy
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
Programming Homework Help
 
Mi 103 linked list
Mi 103 linked listMi 103 linked list
Mi 103 linked listAmit Vats
 
Link list part 2
Link list part 2Link list part 2
Link list part 2
Anaya Zafar
 
Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
J.T.A.JONES
 

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

Linked List data structure
Linked List data structureLinked List data structure
Linked List data structure
Marcus Biel
 
Link List
Link ListLink List
Link List
umiekalsum
 
Linked list
Linked listLinked list
Linked list
Lovelyn Rose
 
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
 
Linked list
Linked listLinked list
Linked list
Md. Afif Al Mamun
 
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
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 
Linked list
Linked listLinked list
Linked list
Trupti Agrawal
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Georgia's location
Georgia's locationGeorgia's location
Georgia's location
Donald Southerland
 
agi software solutions
agi software solutionsagi software solutions
agi software solutions
srilakshmi491
 
【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 tuitions
learningtutorials123
 
Boots
Boots Boots
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
Excelr8 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 case
Dennis Lyubyvy
 
Print connecté pour booster ses ventes
Print connecté pour booster ses ventesPrint connecté pour booster ses ventes
Print connecté pour booster ses ventes
arvato France
 

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++ 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
noreendchesterton753
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
kudikalakalabharathi
 
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
 
Unit - 2.pdf
Unit - 2.pdfUnit - 2.pdf
Unit - 2.pdf
AravindAnand21
 
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
karlynwih
 
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
 
U2.linked list
U2.linked listU2.linked list
U2.linked list
Ssankett Negi
 
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
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
ilsamaryum
 
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
 
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
Lakshmi 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.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ề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.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

تعلق باللہ Relationship with Allah
تعلق باللہ  Relationship with Allahتعلق باللہ  Relationship with Allah
تعلق باللہ Relationship with Allah
Syeda Javeria
 
Whatsapp
Whatsapp Whatsapp
Whatsapp
Syeda Javeria
 
Haya aur Iman
Haya aur ImanHaya aur Iman
Haya aur Iman
Syeda 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 Islam
Syeda Javeria
 
Phishing
PhishingPhishing
Phishing
Syeda Javeria
 
Management by Objectives
Management by ObjectivesManagement by Objectives
Management by Objectives
Syeda 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
 
Hazrat ibrahim a.s.
Hazrat ibrahim a.s.Hazrat ibrahim a.s.
Hazrat ibrahim a.s.
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 deen
Syeda Javeria
 
Depreciation
DepreciationDepreciation
Depreciation
Syeda Javeria
 
Squid
SquidSquid
Windows Movie Maker Tutorial
Windows Movie Maker TutorialWindows Movie Maker Tutorial
Windows Movie Maker Tutorial
Syeda 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
 

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

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 

Recently uploaded (20)

Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 

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)