//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...
You need to complete a function called insertList. Given list A, list B and an integer n, insertList inserts list B into the middle of list A, after the list value n. NOTE: 1) All positions and indices start from 0. 2) Write your code in the empty function of insertList, DO NOT change anything in the main. Example Assume we are starting with two lists: List A is: 2->3->9->11 List B is: 5->6->8 Insert after node value: 3 Resulting...
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 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...
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....
// 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; ...
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; //...
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...
IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...
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...
I have a C++ code that lets me enter, display and delete a student record. I need to implement a function that prints the average grade score of the students I input. Below is my code and a picture of how my code looks right now. #include<iostream> #include<stdlib.h> using namespace std; //Node Declaration struct node { string name; string id; int score; node *next; }; //List class class list { private: //head...