DAS - Linked List Flashcards

1
Q

Linked list operations?

A
  • create
  • traverse nodes
  • delete node at any place
  • insert node at any place
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Create function of Linked list

A
  • this will be same for all types of Ll

void createLL(){

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

insert function in SLL

A
  • Insert node in SLL

void randominsert()
{
int i,loc,item;
struct node *ptr, *temp;
ptr = (struct node *) malloc (sizeof(struct node));
if(ptr == NULL)
{
printf(“\nOVERFLOW”);
}
else
{
printf(“\nEnter element value”);
scanf(“%d”,&item);
ptr->data = item;
printf(“\nEnter the location after which you want to insert “);
scanf(“\n%d”,&loc);
temp=head;
for(i=0;i<loc;i++)
{
temp = temp->next;
if(temp == NULL)
{
printf(“\ncan’t insert\n”);
return;
}

    }  
    ptr ->next = temp ->next;   
    temp ->next = ptr;   
    printf("\nNode inserted");  
}   }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Delete node function in SLL

A
  • Delete node fnc in SLL

void random_delete()
{
struct node ptr,ptr1;
int loc,i;
printf(“\n Enter the location of the node after which you want to perform deletion \n”);
scanf(“%d”,&loc);
ptr=head;
for(i=0;i<loc;i++)
{
ptr1 = ptr;
ptr = ptr->next;

    if(ptr == NULL)  
    {  
        printf("\nCan't delete");  
        return;  
    }  
}  
ptr1 ->next = ptr ->next;  
free(ptr);  
printf("\nDeleted node %d ",loc+1);   }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Search node in SLL

A

void search()
{
struct node *ptr;
int item,i=0,flag;
ptr = head;
if(ptr == NULL)
{
printf(“\nEmpty List\n”);
}
else
{
printf(“\nEnter item which you want to search?\n”);
scanf(“%d”,&item);
while (ptr!=NULL)
{
if(ptr->data == item)
{
printf(“item found at location %d “,i+1);
flag=0;
}
else
{
flag=1;
}
i++;
ptr = ptr -> next;
}
if(flag==1)
{
printf(“Item not found\n”);
}
}

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Display nodes of SLL

A

void display()
{
struct node *ptr;
ptr = head;
if(ptr == NULL)
{
printf(“Nothing to print”);
}
else
{
printf(“\nprinting values . . . . .\n”);
while (ptr!=NULL)
{
printf(“\n%d”,ptr->data);
ptr = ptr -> next;
}
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly