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

16y 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 ); }


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.


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

Input a variable.


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.


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.

Trending Questions
Portland cement dew hardened in bags still ok to use? What does a pressure treated deck board 16 feet weigh? Circuit diagram to operate ac machine in forward and reverse direction? Why longitudinal grooves on bridges? DBMS used in web-based application? The DAGR lacks some of the features that the PLGR has? How do you uprade psp firmware to 3.52 m33-4 I put the file into UPDATE in GAME but when i go to the memory stick icon on the psp it says corrupt data. How do i upgrade? What what did Erna Hoover invent? Why do The pipes keep banging while the water is running? How many cfm are minimum required for welding in a confined space without respirator protection? What is RM analog? What is linkage in c plus plus? What resource is the basis of Swiss manufacturing? BHP to CC relationship how can we relate BHP to CC How can 150CC bike produce 20 BHP where as an 350CC bike just produces 18 BHP? Explain how you can determine the type of correlation for a set of data pairs by examining the data in a table without drawing a scatter plot? How do you write a Java program to implement weighted queue using circular doubly linked list? What is the best test series for IIT JEE advance Resonance Bansal Allen Narayana or FIITJEE? Which modulation can reduce the noice of signal? How do you remove drywall mud that has been painted over from concrete Basement walls need to be bare concrete to apply sealer been scraping help? What is a machine made up from two or more simple machines?