Implement singlylinked list operations operations insert(x) delete(x)and member(
ID: 672199 • Letter: I
Question
Implement singlylinked list operations operations insert(x) delete(x)and member(x) in Java. The linked list should consist of two arrays next and key, both under the structure L ,and containing n positions. The list should also
manage garbage collection. For example, to access the 5th element in the array key, you would
use L.key(5),while to access the 7th position of the array you would use L.next(7).List L should also contain variables head and free. Once the list is created, it should be seen as global in functions insert, delete and member. In particular, the functions should be initialized as:
[indicator] = insert(x), where x is an element and indicator is 0 if insertion was suc
cessful and 1 if the list is full;
[indicator] = delete(x). Variable indicator should be returned as 0 if deletion was suc
cessful, 1 if the list is empty and 2 if an element could not be found.
[indicator] = member(x), where x is an element and indicator is 1 if it is contained in
the list and 0 otherwise.
Explanation / Answer
void fun1(struct node* head)
{
if(head == NULL)
return;
fun1(head->next);
printf("%d ", head->data);
}
void fun(struct node **head_ref)
{
struct node *temp = NULL;
struct node *current = *head_ref;
while (current != NULL)
{
temp = current->prev;
current->prev = current->next;
current->next = temp;
current = current->prev;
}
if(temp != NULL )
*head_ref = temp->prev;
}