FUNCTION
//defination of create mehod
//it will generate characters from c to w and store these in
linklist and finally return it
struct list * create(struct list *node) /*LOGIC TO CREATE A LINK
LIST*/
{
char ch='y';
int i,n;
start.next = NULL; //assign NULL to the start
node
node = &start; /* Point to the start of the list
*/
for(i=1;i<=8;i++) //loop to generate 8 random values and store
them in list
{//allocate a memory for a new node
node->next = (struct list* )
malloc(sizeof(struct list));
node = node->next; //shift the
pointer to the newly created node
//generate random number between 99
to 119 inclusive
n=(rand() % (119 + 1 - 99)) + 99;
//store the generated number in linklist
node->info=n;
node->next = NULL; //assign NULL
to end
}
return node; //retur the list
}
PROGRAM
# include <stdio.h>
# include <stdlib.h>
//structure of a node
struct list
{
char info;
struct list *next;
};
//declare the structure variables
struct list start, *first, *new;
//create method
struct list * create(struct list *);
//display method
void display(struct list *);
void main() /* DEFINATION OF MAIN()*/
{
struct list *node;
//call to create method
node=create(node);
//call to display method
display(node);
}
//defination of create mehod
//it will generate characters from c to w and store these in
linklist and finally return it
struct list * create(struct list *node) /*LOGIC TO CREATE A LINK
LIST*/
{
char ch='y';
int i,n;
start.next = NULL; //assign NULL to the start
node
node = &start; /* Point to the start of the list
*/
for(i=1;i<=8;i++) //loop to generate 8 random values and store
them in list
{//allocate a memory for a new node
node->next = (struct list* )
malloc(sizeof(struct list));
node = node->next; //shift the
pointer to the newly created node
//generate random number between 99
to 119 inclusive
n=(rand() % (119 + 1 - 99)) + 99;
//store the generated number in linklist
node->info=n;
node->next = NULL; //assign NULL
to end
}
return node; //retur the list
}
//display method
void display(struct list *node)
{
/*DISPLAY THE LINKED
LIST*/
node = start.next; //point to the first node
oflist
printf("\n The generated list is as
follows:\n");
while (node) //loop will continue till end
{
printf(" %c ", node->info);
//display the character
node = node->next;//shift the
pointer to next node
}
}
OUTPUT
NOTE: SINCE YOU ARE NOT MENTIONED IN ANY LANGUAGE SO I HAVE DONE IT USING C-LANGUAGE. BUT ANY WAY THE FUNCTION WILL WORK FOR ALL SIMPLY YOU HAVE TO CHANGE THE PRINTF() STATEMENT.
write the function definition to create a linked list of 8 nodes that contain randomly generated...
in c++ only. second part of the first question.
M
is a linked list. this question as well as 3 and 4 are built off of
question 1.
2. Write a function definition to create a new list. sub, that is a subset of M. Return the new list to the calling function.
2. Write a function definition to create a new list. sub, that is a subset of M. Return the new list to the calling function.
Write a function to implement linked list consisting of five nodes. Store the data in the nodes in the order given below. Also, write a function to display the data stored in the implemented linked list. in C++ programming George, Paul, Ross, Joe, Elaine, Robert1 Insert three nodes in between second node and third node in the linked list that you implemented in problem 1. Store the following data in the new (inserted) nodes in the following order. (You have...
Using an appropriate definition of ListNode, design a simple linked list class called StringList with the following member functions: void add (std::string); int positionOf (std::string); bool setNodeVal(int, std::string); std::vector<std::string> getAsVector(); a default constructor a copy constructor a destructor The add() function adds a new node containing the value of the parameter to the end of the list. The positionOf() function returns the (zero-based) position in the list for the first occurrence of the parameter in the list, or -1 if...
Assume we have a linked list with 12 nodes pointed to by FIRST. Write a function that deletes the first node. Write a function that deletes the 7th node. Write a function that deletes the last node.
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...
Assume you are working with a stack implementation of the linked list definition pasted below, write a member method “pop”. The method should return a value (in the “popped” node). Assume the existence of the node references called “TheStack” and “Top”. These references point to the start (or bottom) and top of the stack (or back of the list). ------- Definition: class node { boolean data; node link; }
***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...
Please use C++
CS3358 Insert and delete a node Programming Project 2: The linked list - Reference: chapter 18: Create an array of 15 student records that should not be sorted Create a liked list of 15 student record nodes. Each node is a node of one student record from the above unsorted array. The list of student records should be sorted by student ID. (Insert function without sort function to create a linked list.) (If you insert correctly, the...
2) (10 pts) Write a function that takes in a pointer to a linked list of nodes storing integers and a variable named value, and returns the number of nodes in the list storing that value. For example, if a list pointed to by listPtr stores 2, 6, 2, 3, 4, 2, 6, and 6 and value = 6, your function should return 3, since 6 appears in the list 3 times. Please use the struct and function prototype provided...
PLEASE USE C++ Source Code
Attached is a linked list with 2 nodes. You can use this or
write a similar one. The assignment is to write 2 functions. One
function will add another node at the end of the list. The other
function will delete a node. Don't forget - No dangling pointers
!
Example linked source code attached below
#include<iostream>
using namespace std;
class Node
{
int data;
Node *next;
public:
void setdata(int d) {data = d;}
void...