
//C++ program
#include<iostream>
using namespace std;
struct node{
int data;
struct node*next;
};
struct node* addNode(struct node*list,int data){
struct node*newnode = new(struct node);
newnode->data = data;
newnode->next=NULL;
if(!list)return newnode;
struct node*current = list;
while(current->next)current=current->next;
current->next = newnode;
return list;
}
void print(struct node*list){
while(list){
cout<<list->data<<"
";
list=list->next;
}
cout<<"\n";
}
void
combineLists(node*&pHead,node*pHeadA,node*pHeadB){
while(pHeadA&&pHeadB){
pHead =
addNode(pHead,pHeadA->data+pHeadB->data);
pHeadA = pHeadA->next;
pHeadB = pHeadB->next;
}
while(pHeadA){
pHead =
addNode(pHead,pHeadA->data);
pHeadA = pHeadA->next;
}
while(pHeadB){
pHead =
addNode(pHead,pHeadB->data);
pHeadB = pHeadB->next;
}
}
int main(){
node* pHead = NULL;
node* pHeadA = NULL;
node* pHeadB = NULL;
pHead = addNode(pHead,2);
pHead = addNode(pHead,3);
pHead = addNode(pHead,5);
pHead = addNode(pHead,6);
pHead = addNode(pHead,8);
pHead = addNode(pHead,9);
pHead = addNode(pHead,11);
cout<<"List is : \n";
print(pHead);
pHeadA = addNode(pHeadA,1);
pHeadA = addNode(pHeadA,3);
pHeadA = addNode(pHeadA,4);
pHeadA = addNode(pHeadA,7);
cout<<"\nList A is : \n";
print(pHeadA);
pHeadB = addNode(pHeadB,2);
pHeadB = addNode(pHeadB,4);
pHeadB = addNode(pHeadB,6);
pHeadB = addNode(pHeadB,10);
cout<<"\nList B is : \n";
print(pHeadB);
pHead = NULL;
combineLists(pHead,pHeadA,pHeadB);
cout<<"\nCombine List is : \n";
print(pHead);
return 0;
}
//sample output

Can you make simple code of this using C++ In-lab Final Exam Ideas: Following are the possible topics for the in-lab final exam for next week. These all assume that we have: struct Node int data...
Modify the below code to fit the above requirements:
struct node
{
char data;
struct node *next;
struct node *previous;
} *front, *MyNode, *rear, *MyPointer, *anchor *Valuenode ;
typedef struct node node;
int Push(char input)
{
if(IsFull()==1)
{
printf("The queue is full. Enter the ‘^’ character to
stop.\n");
return -1;
}
else if (IsFull()==-1)
{
node *MyNode=(node*)malloc(sizeof(node));
MyNode->data=input;
rear->next=MyNode;
MyNode->previous=rear;
MyPointer=rear=MyNode;
return 1;
}
else
{
node *MyNode=(node*)malloc(sizeof(node));
node *anchor=(node*)malloc(sizeof(node));
MyNode->data=input;
MyPointer=rear=front=MyNode;
MyNode->previous=NULL;
MyNode->next=NULL;
anchor->next=MyNode;
return 0;
}
}
char...
Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...
In this lab, using C++, you will create an abstract data type, using a doubly-linked circular structure to store the values and links. You must create it by your own and not use any existing containers. You will need a QueueNode. You can use a struct for this, as each node will not have any associated functions. It will have members for data, and the next and previous pointers. Data will be positive integers. There will be no NULL pointers....
Using C Please comment
Part 1: BST Create a link based Binary Search tree composed of a Node and a Tree struct. You should have a header file, BST.h, with the following: o Node struct containing left, right, and parent pointers, in addition to holding an Data struct value Tree struct containing a pointer to the root of the tree A function declaration for a function that allocates a tree, and initializes the root to NULL o o o A...
starter code
To write a program using the starter code which is
TestLinkedList to see if the LinkedList program has bugs. It will
produce ether a pass or fail.More information is in the first two
pictures.
LinkedList.java
/**
* @author someone
*
* Implements a double-linked list with four errors
*/
public class LinkedList<E>
{
// The first and last nodes in the list
private Node<E> head, tail;
// Number of items stored in the list
private int size;
//...
In this assignment you are to utilize the Node data structure provided on Blackboard. In this assignmet you are to write a main program that implements two methods and a main method as their driver. So, only main and two methods with it. Note: You may not use any of the LinkedList class provided on Blackboard, you may use the methods in it as a guide (you should actually look at them) but you cannot use any of the methods...
Data Structures - Singly Linked Lists You will add a method swapNodes to SinglyLinkedList class (below). This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same node, etc. Write the main method to test the swapNodes method. You may need to traverse the list. package linkedlists; public class SinglyLinkedList<E> implements Cloneable { // ---------------- nested Node class...
// C code // If you modify any of the given code, the return types, or the parameters, you risk getting compile error. // Yyou are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable: 4996) // for Visual Studio #define MAX_NAME 30 // global linked list 'list' contains the list of patients struct patientList { struct patient *patient; struct patientList *next; } *list = NULL; ...
Using C++ in Visual Studios
Rewrite the code to use a Stack instead of a Queue. You will
need to think about the differences in the Stack and Queue. Think
about how they operate and how the nodes may differ.
Modify the code as necessary.
You will need to push to the Stack, pop from the Stack, peek at
the Stack. You will need a member functions like in the example
code. Your program will need to show that everything...
Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...