Explanation of Solution
The program has been explained in the in-lined comments:
#include <iostream>
using namespace std;
int main()
{
//delcare a list and initialize it
//with an array of 6 elements
int numList[6] = {25, 37, 62, 78, 92, 13};
//create a pointer to the list -
//the base address of the list is assigned
//to the pointer
int *listPtr = numList;
//a new pointer is declared and is assigned
//an address 2 int positions incremented i.e
//it points to the 3rd position in the array
//or numlist[2] which is the value 62
int *temp = listPtr + 2;
//declare an int variable
int num;
//assign value of the memory address pointed to
//by listPtr with the arithmetic expression on the
//RHS of the assignment operator
//RHS = *(listPtr + 1) - *listPtr =
//numList[1] - numList[0] = 37-25 = 12
//since listPtr is numList[0] so now the array elements
//are {12, 37, 62, 78, 92, 13}
*listPtr = *(listPtr + 1) - *listPtr;
//listPtr is incremented and now points to numList[1]
// i.e. 37
listPtr++;
//num is assigned the value pointed to by temp which is
//numList[2] i.e. 62
num = *temp;
//temp is incrementedand now points to numList[3]
//i...
Want to see the full answer?
Check out a sample textbook solutionChapter 12 Solutions
Mindtap Computing, 1 Term (6 Months) Printed Access Card For Malik's C++ Programming: From Problem Analysis To Program Design, 8th (mindtap Course List)
- struct Node { int data; Node * next; }; Node • head; a. Write a function named addNode that takes in a variable of type int and inserts it at the head of the list. b. Write a function named removeNode that removes a node at the head of the list.arrow_forwardC language. Function write the arraylist_sort function This generic function sorts an array list using the given compare function. l An array list compare Pointer to the function which compares two elements If you cannot write down a generic function which works for all types, write down a function which sorts resturants. If you cannot use function pointers, you can write down multiple functions which sort using different criteria.arrow_forwardQ: Convert this to sorted array #include<iostream> #include"Student.cpp" class StudentList { private: struct ListNode { Student astudent; ListNode *next; }; ListNode *head; public: StudentList(); ~StudentList(); int IsEmpty(); void Add(Student newstudent); void Remove(); void DisplayList(); }; StudentList::StudentList() { head=NULL; }; StudentList::~StudentList() { cout <<"\nDestructing the objects..\n"; while(IsEmpty()!=0) Remove(); if(IsEmpty()==0) cout <<"All students have been deleted from a list\n"; }; int StudentList::IsEmpty() { if(head==NULL) return 0; else return 1; }; void StudentList::Add(Student newstudent) { ListNode *newPtr=new ListNode; if(newPtr==NULL) cout <<"Cannot allocate memory"; else { newPtr->astudent=newstudent; newPtr->next=head; head=newPtr; } }; void StudentList::Remove() { if(IsEmpty()==0) cout <<"List empty on remove"; else { ListNode *temp=head;…arrow_forward
- SKELETON CODE IS PROVIDED ALONG WITH C AND H FILES. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include "node.h" #include "stack_functions.h" #define NUM_VERTICES 10 /** This function takes a pointer to the adjacency matrix of a Graph and the size of this matrix as arguments and prints the matrix */ void print_graph(int * graph, int size); /** This function takes a pointer to the adjacency matrix of a Graph, the size of this matrix, the source and dest node numbers along with the weight or cost of the edge and fills the adjacency matrix accordingly. */ void add_edge(int * graph, int size, int src, int dst, int cost); /** This function takes a pointer to the adjacency matrix of a graph, the size of this matrix, source and destination vertex numbers as inputs and prints out the path from the source vertex to the destination vertex. It also prints the total cost of this…arrow_forwardHomework Assignment-1Topics: Functions, Dictionary, ImportProblem description: Write a python application to simulate an online clothing system. Thepurpose of this assignment is to gain experience in Python dictionary structure, create basicPython functions and import a module.Design solution: The template file contains a list of clothes item sold, each item in the listcontains the item id, name of the item and the prices. The program will generate an items_dictwhere each key is the item id of the cloth and the values will be a list of item name and priceinformation. A customer will be presented with a main menu with 4 different options: displayall items, add an item to cart, checkout and exit the program. A customer can buy an item byentering the ID of the item. This program implements a dictionary called cart, where each key isthe item id and the values are the list of name, price and quantity that user chooses topurchase. The program keeps repeating by displaying the main menu to…arrow_forwardIf you have the following node declaration: struct Node { int number; struct Node * next; }; typedef struct Node node; node *head,*newNode; Write a C program that contains the following functions to manipulate this linked list : First function: Adding the odd numbers to the beginning of the list and even numbers to the end of the list until -1 is entered from keyboardarrow_forward
- create a queque array in c++ where it user will have a choice whether to insert name in queque, delete name in queque, determone who's in front and who's at back of the queue and display all names in queuearrow_forwardstruct node{ int a; struct node * nextptr; }; Write two functions. One for inserting new values to a link list that uses the given node structure. void insert(struct node **head, int value); Second function is called to count the number of even numbers in the link list. It returns an integer that represents the number of even numbers. int countEvenNumbers(struct node *head); Write a C program that reads a number of integers from the user and insert those integers into a link list (use insert function). Later pass the head pointer of this link list to a function called countEvenNumbers. This function counts and returns the number of even numbers in the list. The returned value will be printed on the screen. Note 1: Do not modify the function prototypes. Sample Input1: Sample Output1: 45 23 44 12 37 98 33 35 -1 3 Sample Input2: Sample Output2: 11 33 44 21 22 99 123 122 124 77 -1 4arrow_forward{JAVA data structure set} Suppose you have a list of numbers: numbers = [1, 2, 13, 4, 4, 5, 5, 6, 6, 7, 7, 12] Convert this list into a set and assign it to a new variable called unique_numbers. Print unique_numbers to see the result.arrow_forward
- struct insert_at_back_of_dll { // Function takes a constant Book as a parameter, inserts that book at the // back of a doubly linked list, and returns nothing. void operator()(const Book& book) { / // TO-DO (2) |||| // Write the lines of code to insert "book" at the back of "my_dll". // // // END-TO-DO (2) ||| } std::list& my_dll; };arrow_forwardC CodeApproved Libraries:<string.h> *not allowed in some questions<math.h><stdlib.h><time.h> (for srand(time(0)) only)arrow_forwardstruct nodeType { int infoData; nodeType * next; }; nodeType *first; … and containing the values(see image) Using a loop to reach the end of the list, write a code segment that deletes all the nodes in the list. Ensure the code performs all memory ‘cleanup’ functions.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education