answersLogoWhite

0

Starting with a pointer to the pointer to the first element (p1**), verify the first pointer is not null (*p1 != null), retrieve the pointer to the second element (*p2 = *p1.next) and verify it is also not null (*p2 != null), and then retrieve the pointer to the third element (*p3 = *p2.next). Note that *p3 might be null, but *p1 and *p2 must not be null, or the swap can not be performed. Note that using pointer to pointer syntax allows you to treat pointer to first element the same as pointer to subsequent element, i.e. to not need to handle the special case. Also, since you do need to modify the pointer, you need a pointer to the pointer. Set *p1 = *p2, *p3 = *p1, and *p2 = *p3. Note that these assignments must be done using the original values, not the intermediate value, so you will need some temp pointers. The end result is that **p1 will be ordered after **p2.

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering
Related Questions

Call by reference using pointer in c plus plus?

Example: void foo( MyClass& object ){} // function with call by reference signature MyClass* p = new MyClass(); // instantiate a pointer to MyClass foo( *p ); // call by reference using the pointer


Swapping of two nos using pointer in c plus plus?

There is no benefit in swapping two numbers using a pointer. It's actually quicker to swap the two numbers themselves. However the following shows how to swap values by changing the pointers to those value. #include <iostream> int main() { int X = 5; int Y = 6; // Point to the values in X and Y. int *pX = &X; int *pY = &Y; // Print current values and the values being pointed at: std::cout << "Before swapping:" << std::endl; std::cout << " X = " << X << ", Y = " << Y << std::endl; std::cout << "pX = " << *pX << ", pY = " << *pY << std::endl; // Swap the pointers. pX = &Y; pY = &X; // Print current values and the values being pointed at: std::cout << "After swapping:" << std::endl; std::cout << " X = " << X << ", Y = " << Y << std::endl; std::cout << "pX = " << *pX << ", pY = " << *pY << std::endl; return( 0 ); }


Add two numbers in pointer in using c plus plus?

int* a = new int(40); int* b = new int(2); int x = *a + *b; // x = 42 delete b; delete a;


What is Dazzling Pointer in c plus plus?

The pointer that points to a block of memory that does not exist is called a dazzling pointer or wild pointer


Find the greater no between two nos using pointer in c plus plus programming?

if (*&a > *&b) *&max = *&a; else *&max = *&b;


What is 'this' pointer in c plus plus?

Address of the current object.


Why pointer is used to reference a string of characters write C plus plus statements that display the text hello using pointer to a string notation?

We use a pointer to reference a string because a string is an array of characters where every element is a char (or a wchar_t if using UNICODE strings). Passing arrays by value would require the entire array to be copied, but passing a pointer variable to an array only copies the pointer, which is effectively the same as passing the array by reference. #include <iostream> int main() { char * psz = "hello"; // pointer to a null-terminated string. std::cout << psz; // pass the pointer (by value) to the insertion operator. return( 0 ); }


How do you alternate the input numbers using for loop in c plus plus?

Input a variable.


What is null object in c plus plus?

a pointer that is not pointing to anything


What changes the pointer to a plus icon in excel?

The application does that when the pointer is over the cells region of the spreadsheet.


Which function is used to determine the position of the put pointer in a file in c plus plus?

The function ftell returns the position of the file pointer for a file.


What does multiplying a pointer by 5 in C plus plus mean How does it change the pointer's value?

Multiplication is yet another thing, what you should never do with pointers.