//################################## PGM START ####################################
#include<stdio.h>
#include<stdlib.h>
//structure with a integer value and next pointer
struct node{
int value;
struct node *next;
};
//function which cretes a newnode
struct node* create_node(int data){
struct node* newnode=(struct node*)
malloc(sizeof(struct node));
newnode->value = data;
newnode->next = NULL;
return newnode;
}
//function to insert a data to list pointed by head
void insert(struct node **head,int data){
struct node* n1=create_node(data);
n1->next=*head;
*head=n1;
}
//function to print values in list
void printLinkedList(struct node* head){
while(head->next!=NULL){
printf("%d -->
",head->value);
head=head->next;
}
printf("%d\n",head->value);
}
//main method
int main(){
//creatin a head pointer
struct node* head=NULL;
//inserting values to list
insert(&head,1);
insert(&head,2);
insert(&head,10);
insert(&head,3);
//prinitng values in list
printf("List elements\n");
printLinkedList(head);
return 0;
}
//################################# PGM END #######################################
OUTPUT
##########
Linked list is a type of data structure. Each item of the list holds a data...
In C++
Assume entries in a linked list are of type struct
listrec:
struct listrec
{
struct listrec *prev;
float
value;
struct listrec *next;
};
listrec *head, *tail;
Write a main() routine in which the user is asked the
number of nodes to create in the list (number greater than or equal
to zero) then create the following type of linked list (use a loop
to initialize list) based on the number of nodes requested:
Write a...
C++ Create a class that implements a sorted, doubly-linked list: Start with a copy of the sortedList class. Call your new class doublyLinkedList. Convert the baseline code into a doubly linkedlist, and thoroughly test all existing operations (make sure to check all edge conditions), and then implement the new operations below. The class should have the following additional class methods: • A reverse method: this method will reverse the order of the doubly linked list. This method takes no parameters,...
***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful. Also note that the function must work no matter how many nodes...
implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...
Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...
Using a doubly linked list as the underlying data structure, implement a list ADT that implements the ListInterface.java found in the ProgProjTwo Eclipse project starting point for this assignment. In addition to the forward iterator defined by resetIterator( ) and getNextItem( ) in ListInterface.java, implement a backwards iterator by providing resetBackIterator( ) and getPreviousItem( ) methods. As noted in the syllabus addendum, you are encouraged to develop a find( ) helper method that can support various list ADT operations. A...
Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...
Given the node structure and the head pointer (headptr) of a linked list write a code to move the last element to the head of the list. struct node { int value; struct node *next; };
Problem Statement This problem provides you with a linked list composed of node objects chained together via node pointers. Each node has a next pointer which points to the next node in the chain. The last node is identified by having a NULL (or nullptr) next pointer. The linked lists for this problem store string data. Your task: identify the longest string stored in the linked list. If two strings are of the same length, return the string that occurred...
Answer all questions
1- in circular singly linked list, previous pointer of the first node points to which node A. First node B. Itself C. null D. Last node 2- Which of the following is NOT an applications of linked lists? A. Implementation of stacks and queues B. Dynamic memory allocation C. Manipulation of polynomials D. Keeping people at home during epidemics like corona virus 3- In a circular singly linked list? A. Components are all linked together in some...