Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

1.

void beginsert()

2. {

3. struct node *ptr,*temp;

4. int item;

5. ptr = (struct node *)malloc(sizeof(struct node));

6. if(ptr == NULL)

7. {

8. printf("\nOVERFLOW");

9. }

10. else

11. {

12. printf("\nEnter the node data?");

13. scanf("%d",&item);

14. ptr -> data = item;

15. if(head == NULL)

16. {

17. head = ptr;

18. ptr -> next = head;

19. }

20. else

21. {

22. temp = head;

23. while(temp->next != head)

24. temp = temp->next;

25. ptr->next = head;

26. temp -> next = ptr;

27. head = ptr;

28. }

29. printf("\nnode inserted\n");

30. }

31.

32. }
1.
void lastinsert()

2. {

3. struct node *ptr,*temp;

4. int item;

5. ptr = (struct node *)malloc(sizeof(struct node));

6. if(ptr == NULL)

7. {

8. printf("\nOVERFLOW\n");

9. }

10. else

11. {

12. printf("\nEnter Data?");

13. scanf("%d",&item);

14. ptr->data = item;

15. if(head == NULL)

16. {

17. head = ptr;

18. ptr -> next = head;

19. }

20. else

21. {

22. temp = head;

23. while(temp -> next != head)

24. {

25. temp = temp -> next;

26. }

27. temp -> next = ptr;

28. ptr -> next = head;

29. }

30.

31. printf("\nnode inserted\n");

32. }

33.
1.
void begin_delete()
2. {
3. struct node *ptr;
4. if(head == NULL)
5. {
6. printf("\nUNDERFLOW");
7. }
8. else if(head->next == head)
9. {
10. head = NULL;
11. free(head);
12. printf("\nnode deleted\n");
13. }
14.
15. else
16. { ptr = head;
17. while(ptr -> next != head)
18. ptr = ptr -> next;
19. ptr->next = head->next;
20. free(head);
21. head = ptr->next;
22. printf("\nnode deleted\n");
23.
24. }
1.
void last_delete()
2. {
3. struct node *ptr, *preptr;
4. if(head==NULL)
5. {
6. printf("\nUNDERFLOW");
7. }
8. else if (head ->next == head)
9. {
10. head = NULL;
11. free(head);
12. printf("\nnode deleted\n");
13.
14. }
15. else
16. {
17. ptr = head;
18. while(ptr ->next != head)
19. {
20. preptr=ptr;
21. ptr = ptr->next;
22. }
23. preptr->next = ptr -> next;
24. free(ptr);
25. printf("\nnode deleted\n");
26.
27. }
28. }
1.
void display()
2. {
3. struct node *ptr;
4. ptr=head;
5. if(head == NULL)
6. {
7. printf("\nnothing to print");
8. }
9. else
10. {
11. printf("\n printing values ... \n");
12.
13. while(ptr -> next != head)
14. {
15.
16. printf("%d\n", ptr -> data);
17. ptr = ptr -> next;
18. }
19. printf("%d\n", ptr -> data);
20. }

You might also like