//16 CODE HAS BEEN IMPLEMENTED, DO CHECK ONCE BY YOUR OWN
/*
struct NodeType{
ComponentType component;
NodePtr link;
}
NodePtr listPtr;
NodePtr currPtr;
NodePtr newNodePtr;
*/
void sortList(){
if(listPtr == null){
return;
}
NodePtr newListPtr = null;
NodePtr newCurrPtr = null;
NodePtr curr = listPtr;
Nodeptr temp,prev;
while(curr!=null){
prev = null;
temp = curr;
while(curr->link){
if(
(temp->component) > (curr->link->component) ){
temp = curr->link;
prev=curr;
curr=curr->link;
}
}
//CREATE NODE --- THIS FOR CREATING
NEW NODE
/*
struct NodePtr newNodePtr = (struct
NodePtr) malloc(sizeof(struct NodeType));
newNodePtr->component =
temp->component;
*/
if(newListPtr == null){
newListPtr =
temp;
newCurrPtr =
temp;
}else{
newCurrPtr->link=temp;
newCurrPtr=temp;
}
//MOVE NODE
if(prev == null){
listPtr =
listPtr->link;
temp->link =
null;
}else{
prev->link =
temp->link;
temp->link =
null;
}
//REMOVE NODE --- THIS IS FOR
DELETING NODE
/*
if(prev==null){
listPtr =
listPtr->link;
free(temp);
}else{
prev->link =
temp->link;
free(temp);
}*/
curr = listPtr;
}
listPtr = newListPtr;
currPtr = newListPtr;
}
16 and 18 C++ 11. Given the dynamic linked implementation of a linked list shown below,...
The source code I have is what I'm trying to fix for the assignment at the bottom. Source code: //Group 1 - Jodie Butterworth, Brandon Kidd, Matt Heckler //11-21-19 //CSC 201 // Exercise to practice the basic manipulations of a linked list // Note: Uses nullptr, so need to make sure your compiler is set to use C++11 // In Code::Blocks this is under Settings==>Compiler #include <iostream> using namespace std; // Structure to contain data for a node (Could be...
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...
linked list operation
/***************************************************************************************
This function creates a new node with the information give as a parameter and looks
for the right place to insert it in order to keep the list organized
****************************************************************************************/
void insertNode(string first_name, string last_name, string phoneNumber)
{
ContactNode *newNode;
ContactNode *nodePtr;
ContactNode *previousNode = nullptr;
newNode = new ContactNode;
/***** assign new contact info to the new node here *****/
if (!head) // head points to nullptr meaning list is empty
{
head = newNode;...
() Given the following structure definition and typedef for a linked list of strings: typedef struct node st node; struct node st { char *word; /* a valid string pointer or NULL */ node *next; /* next node in the list or NULL */ }; Write a C function, free list(), that takes as an argument one of these lists, possibly NULL, and frees all the strings as well as the list itself. Write robust code. void free list(node *list){
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 the provided Linked List template, add the following recursive functions and demonstrate them in a separate cpp file. Write a recursive function to print the list in order. Write a recursive function to print the list in reverse order. Write a recursive function to print every other node in the list in order. Write a recursive function to return the number of nodes in the list. Write a Boolean function that implements the recursive version of sequential search. THIS...
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; };
CSCI 2010 Lab11 Link-Lists
Lab 11A Linked-Lists
Preparation
Create a Visual Studio C++ Project C2010Lab11A
Add the following to the project.
//LinkedList.cpp
#include <cstdlib>
#include "LinkedList.h"
using namespace std;
//---------------------------------------------------
//List Element Members
//---------------------------------------------------
ListElement::ListElement(int d, ListElement * n)
{
datum=d;
next=n;
}
int ListElement::getDatum () const
{
return datum;
}
ListElement const* ListElement::getNext () const
{
return next;
}
//---------------------------------------------------
//LinkedList Members
//---------------------------------------------------
LinkedList::LinkedList ()
{
head=NULL;
}
void LinkedList::insertItem(int item)
{
ListElement *currPtr = head;
ListElement *prevPtr =...
PART 1 Implement a C++ class for an array representation of a list. The methods must be based upon the pseudocode provided on the CS210 Algorithms below. Use the following declarations as a starting point for your implementation. const int MAX_LENGTH = some application-specific max value; typedef <some data type> DataType; class List { public: methods go here private: int p; int length; DataType a [MAX_LENGTH]; }; Note: Any other variable or constant declarations required would...
41. True or False? Searching the components of an unordered list
ADT is faster with a linked list representation than with a direct
array representation.
a) true
b) false
42. True or False? If an operation that allows random access to
individual components of a list ADT is defined and occurs
frequently, it is better to represent the list directly as an array
than to use a linked list.
a) true
b) false
43. To prevent a compile-time error, how...