I need help with encoding a doubly-linked list, which must include a function that sorts the name field in the bubble method, it must be encoded in the c language.
The program for sorting the double linked list with the bubble method is given below,
#include <stdio.h>
struct ddnode{
int num;
struct ddnode *prev;
struct ddnode *next;
};
struct ddnode *head, *tail = NULL;
//insertNode() will add a ddnode to the list
void insertNode(int num) {
//Create a new ddnode
struct ddnode *newDnode = (struct ddnode*)malloc(sizeof(struct
ddnode));
newDnode->num = num;
if(head == NULL) {
//Both head and tail will point to newDnode
head = tail = newDnode;
//head's prev will point to NULL
head->prev = NULL;
//tail's next will point to NULL, as it is the last ddnode of the
list
tail->next = NULL;
}
else {
//newDnode will be added after tail such that tail's next will
point to newDnode
tail->next = newDnode;
//newDnode's prev will point to tail
newDnode->prev = tail;
//newDnode will become new tail
tail = newDnode;
//As it is last ddnode, tail's next will point to NULL
tail->next = NULL;
}
}
//sortDoubleLinkedList() will sort the given list in ascending
order
void sortDoubleLinkedList() {
struct ddnode *curr = NULL, *index = NULL;
int temp;
//Check whether list is empty
if(head == NULL) {
return;
}
else {
//Current will point to head
for(curr = head; curr->next != NULL; curr = curr->next)
{
//Index will point to ddnode next to curr
for(index = curr->next; index != NULL; index = index->next)
{
//If curr's num is greater than index's num, swap the num of curr
and index
if(curr->num > index->num) {
temp = curr->num;
curr->num = index->num;
index->num = temp;
}
}
}
}
}
//printList() will print out the nodes of the list
void printList() {
//Node curr will point to head
struct ddnode *curr = head;
if(head == NULL) {
printf("List is empty\n");
return;
}
while(curr != NULL) {
//Prints each ddnode by incrementing pointer.
printf("%d ",curr->num);
curr = curr->next;
}
printf("\n");
}
int main() {
//adding the nodes in thr list
insertNode(4);
insertNode(3);
insertNode(9);
insertNode(1);
insertNode(2);
insertNode(8);
// original list
printf("Original list: \n");
printList();
//Sorting operation
sortDoubleLinkedList();
// sorted list
printf("Sorted list: \n");
printList();
return 0;
}
SCREENSHOT



I need help with encoding a doubly-linked list, which must include a function that sorts the...
I
already created a doubly linked list class. I need help doing this
and adding the doubly linked list class to this. I need this for
Java language if someone can please help me
Step 2 Stack and Queue Using the linked list class you created in Step 1 create stack and queue classes. Iwill leave it up to you as to whether to use composition or inheritance but whatever way you choose to go you should be able to...
Using C++ language, Design and implement a class representing a doubly linked list. The class must have the following requirements: The linked list and the nodes must be implemented as a C++ templates The list must be generic – it should not implement arithmetic/logic functions. (template class) It must include a destructor and a copy constructor It must include methods to insert at the front and at the back of the list It must include a method to return the...
JAVA please Java problem that has to be in doubly linked list. It is game problem that I have to keep of the players' scores. this should have a Java blueprint class named player It should have two fields, the name and score and include the constructors, toString() method, and getters and setters. Scores must be kept in ascending order (smallest at the front ) in a doubly linked list. It has menu as well: Load original data Print the...
implement delete node function in c++ language
I
just need a basic doubly linked list code for the delete node
portion of the code
// Delete node containing word from list if it is present void delNode (DLList list, char *str) (
// Delete node containing word from list if it is present void delNode (DLList list, char *str) (
This class implements a doubly linked list in which the nodes are of the class DLNode. This class must implement the interface DLListADT.java that specifies the public methods in this class. The header for this class will then be public class DLList implements DLListADT This class will have three private instance variables: • private DLNode front. This is a reference to the first node of the doubly linked list. • private DLNode rear. This is a reference to the last...
Implement a simple Doubly Linked List using nodes. Functions to include: an insert in a sorted list, and a delete function, including constructor. Please include comments to make the code traceable and understandable
Could anyone help me solve this problem in C++? Write a function that sorts a linked list. (Use any sort algorithm, make sure to state which one your going to use.)
PART 1: Design and implement a class representing a doubly linked list. The class must have the following requirements: 1)The linked list and the nodes must be implemented as C++ templates 2)The list must be generic
Write a C function that iterates through a singly linked list and converts it to a doubly linked list. Your solution must NOT create a second list. You must come up with the appropriate parameters and return type. Note: the nodes in the singly linked list have a field for a previous pointer, but that field has not initially been set in any of the nodes. You must do this as part of your solution!
C LINKED LIST #include <stdlib.h> #include <stdio.h> //Struct for a polynomial term (double linked list object) typedef struct Polynomial t_Polynomial; typedef struct Term { // coefficient of the polynomial term associated with the object int coef; // power of the polynomial term associated with the object int power; // pointer to the next object (to facilitate a doubly linked list) struct Term *next; // pointer to the previous object (to facilitate a doubly linked list) struct Term...