Question:

Published on: 21 January, 2022

Write a C language function to delete the nth node of a singly-linked list. The error conditions are to be handled properly.

Answer:

Following delete function can be used to delete n-th node from singly linked list. Funtion is written in C.

int delete(node * head, int key) { node * p, * q; int x = 0; p = head; if (p == Null) { printf(“List is empty”); return 0; } else while (p != null && p - > data != key) { q = p; p = p - > next; } if (p == head) { x = key; head = (head) - > next; free(p); } else { If(p - > data == key) { x = p - > data; q - > next = p - > next; free(p); } } } return (x);

Subjects

Trending

Define the ADT for stack. Show the implementation of the stack data structure using linked list.

View : 931

12 October, 2024

What is the benefit of using arrays of pointers instead of several pointer variables?

View : 908

23 January, 2022

a) Define big O notations.

b) \( {T(n) = 4n^{2}+3n \log_{}{n} } \), express T( n ) in Big( O ) notations.

View : 956

12 October, 2024

Write a C language function to find the in-order successor of the root of a binary tree.

View : 712

21 January, 2022

Random questions

**Discuss Analysis Modeling Concepts and Approaches**

12 October, 2024

12 October, 2024

12 October, 2024

**What is Resource management?**

12 October, 2024