Professional Documents
Culture Documents
Ds Link List 2
Ds Link List 2
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
printf ("\n");
}
int main ()
{
struct Node *head = NULL;
return 0;
}
Insertion at the end
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
int
main ()
{
//creating 4 pointers of type struct Node
//So these can point to address of struct type variable
struct Node *head = NULL;
struct Node *node2 = NULL;
struct Node *node3 = NULL;
struct Node *node4 = NULL;
node2->data = 30;
node2->next = node3;
node3->data = 24;
node3->next = node4;
node4->data = 20;
node4->next = NULL;
return 0;
}
//Linked list insertion at specific position in C
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
else
{
// temp used to traverse the Linked List
struct Node *temp = *head;
int main ()
{
node2->data = 20;
node2->next = node3;
node3->data = 30;
node3->next = node4;
node4->data = 40;
node4->next = NULL;
display (head);
display (head);
return 0;
}
struct Node
{
int data;
struct Node *next;
};
int main ()
{
//creating 4 pointers of type struct Node
//So these can point to address of struct type variable
struct Node *head = NULL;
struct Node *node2 = NULL;
struct Node *node3 = NULL;
struct Node *node4 = NULL;
node2->data = 30;
node2->next = node3;
node3->data = 24;
node3->next = node4;
node4->data = 20;
node4->next = NULL;
deleteStart (&head);
deleteStart (&head);
return 0;
}
struct Node
{
int data;
struct Node *next;
};
// not valid
if (n < 1 || n > size)
{
printf ("Enter valid position\n");
return;
}
int main ()
{
//creating 4 pointers of type struct Node
//So these can point to address of struct type variable
struct Node *head = NULL;
struct Node *node2 = NULL;
struct Node *node3 = NULL;
struct Node *node4 = NULL;
struct Node *node5 = NULL;
node2->data = 20;
node2->next = node3;
node3->data = 15;
node3->next = node4;
node4->data = 10;
node4->next = node5;
node5->data = 5;
node5->next = NULL;
display (head);
return 0;
}
Deletion at last node
#include<stdio.h>
#include<stdlib.h>
struct Node
{
int data;
struct Node *next;
};
int main ()
{
//creating 4 pointers of type struct Node
//So these can point to address of struct type variable
struct Node *head = NULL;
struct Node *node2 = NULL;
struct Node *node3 = NULL;
struct Node *node4 = NULL;
struct Node *node5 = NULL;
struct Node *node6 = NULL;
node2->data = 4;
node2->next = node3;
node3->data = 6;
node3->next = node4;
node4->data = 8;
node4->next = node5;
node5->data = 10;
node5->next = node6;
node6->data = 12;
node6->next = NULL;
printf ("Linked list: ");
display (head);
deleteEnd (&head);
deleteEnd (&head);
return 0;
}
1. #include<stdio.h>
2. #include<stdlib.h>
3. struct node
4. {
5. int data;
6. struct node *next;
7. };
8. struct node *head;
9.
10. void beginsert ();
11. void lastinsert ();
12. void randominsert();
13. void begin_delete();
14. void last_delete();
15. void random_delete();
16. void display();
17. void search();
18. void main ()
19. {
20. int choice =0;
21. while(choice != 9)
22. {
23. printf("\n\n*********Main Menu*********\n");
24. printf("\nChoose one option from the following list ...\n");
25. printf("\
n===============================================\n");
Output:
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
Enter value
1
Node inserted
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
Enter value?
2
Node inserted
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
Node inserted
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
printing values . . . . .
1
2
1
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
Enter value?
123
Node inserted
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
Node inserted
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
Enter the location of the node after which you want to perform deletion
1
Deleted node 2
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
printing values . . . . .
1
1
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit
*********Main Menu*********
===============================================
1.Insert in begining
2.Insert at last
3.Insert at any random location
4.Delete from Beginning
5.Delete from last
6.Delete node after specified location
7.Search for an element
8.Show
9.Exit