Question

In: Computer Science

Write a pseudocode function that interchanges two adjacent items of: (a) singly linked lists (b) doubly...

Write a pseudocode function that interchanges two adjacent items of:

(a) singly linked lists

(b) doubly linked lists

if you can make it clean and short that be nice

Solutions

Expert Solution

I assume, the question is to swap all the adjacent terms in a list.

SINGLY LINKED LIST :

FUNCTION SWAP_ITEMS ( head )

    DECLARE first , second , temp , new_head

    first = head

    new_head = first.next

    WHILE ( TRUE )       

           second = first.next

           temp = second.next

           IF temp == NULL or temp.next == NULL

                    p.next = temp

                    break

           END IF

          p.next = temp.next

           p = temp

    END WHILE   

    RETURN new_head

END FUNCTION

=======================================================

OR

========================================================================

b)

Thank you, If you have any doubt ask in commnet section. If you like my effort please upvote.


Related Solutions

Data Structures Homework – Singly Linked Lists Create a singly linked that represents a school. The...
Data Structures Homework – Singly Linked Lists Create a singly linked that represents a school. The school has multiple classes. Each class has a different number of students. class student { Long ID; string Name; string Address; float grades[3]; student *below; }; class Node // the node represents a class in school { int ID; int NoOfStudents; int NoOfQuizes; student *t;// a linked list of students is allocated dynamically Node *Next; }; class school { string Name; Node *Head; int...
I was supposed to conver a singly linked list to a doubly linked list and everytime...
I was supposed to conver a singly linked list to a doubly linked list and everytime I run my program the output prints a bunch of random numbers constantly until I close the console. Here is the code. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> struct node { int data; struct node *next; struct node *prev; }; //this always points to first link struct node *head = NULL; //this always points to last link struct node *tail = NULL;...
HI i will write user's manual for a doubly/singly linked list , How can i write...
HI i will write user's manual for a doubly/singly linked list , How can i write User's manual ?
You are given a singly linked list. Write a function to find if the linked list...
You are given a singly linked list. Write a function to find if the linked list contains a cycle or not. A linked list may contain a cycle anywhere. A cycle means that some nodes are connected in the linked list. It doesn't necessarily mean that all nodes in the linked list have to be connected in a cycle starting and ending at the head. You may want to examine Floyd's Cycle Detection algorithm. /*This function returns true if given...
Write PSEUDOCODE to insert a node at position 2 in a doubly-linked list (assume position follows...
Write PSEUDOCODE to insert a node at position 2 in a doubly-linked list (assume position follows classic indexing from 0 to item_count - 1)
Using the singly linked list code as a base, create a class that implements a doubly...
Using the singly linked list code as a base, create a class that implements a doubly linked list. A doubly linked list has a Previous link so you can move backwards in the list. Be sure the class is a template class so the user can create a list with any data type. Be sure to test all the member functions in your test program. c++
Using C++, you will create a program, where you will create two doubly linked lists. These...
Using C++, you will create a program, where you will create two doubly linked lists. These doubly linked lists will contain integers within them. Using the numbers in both of these linked lists, you add the numbers together, and insert the addition of the two numbers into a singly linked list. the input can be from the user or you just write the input. for example, if one number in the doubly linked list is 817 and in the other...
Write a c++ member function that sequentially searches for a specific element in a doubly linked...
Write a c++ member function that sequentially searches for a specific element in a doubly linked list. return the position if found or -1 is the element cannot be found.
1. Answer “True” or “False”. (a) A doubly linked list structure is worse than a singly...
1. Answer “True” or “False”. (a) A doubly linked list structure is worse than a singly linked list if we plan to do a lot of insertions. (b) A doubly linked list structure is worse than a singly linked list if we plan to do a lot of deletions. (c) A doubly linked list structure is worse than a singly linked list if we plan to print the entire list frequently. (d) An array implementation of a queue is more...
towers of hanoi c++ program using stacks and singly linked lists.
towers of hanoi c++ program using stacks and singly linked lists.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT