answersLogoWhite

0


Best Answer

assuming a circular, doubly linked list that uses its
head pointer as a sentinel (no data is stored in the
head).

#define PTR_SWAP(a, b) \
do { \

const void* t = a; a = b; b = (void*)t; \

} while (0)


void
listReverse(list_type* list) {
node_type* node = list->head;

do {

PTR_SWAP(node->prev, node->next);

node = node->prev;

} while (node != list->head);

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a function in c plus plus to reverse a linked list without using more than constant of extra space?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Using recursion reverse a singly linked list?

Let's suppose your list consists of elements that have an integer part (the data) and a reference (or pointer) to the next list element.Now your function would look like this:void Reverse(listitem){if(listitem.next exists) //you have to check this in a way depending on your implementationReverse(listitem.next); //the function goes right onto the next elementprint(listitem.data); //or do anything that is needed}In a nutshell, this function first explores the whole linked list, and when it reaches the end, the individual function calls reach the data processing block, and then terminate, thus giving the control back to the previous listelement's function call.


How can you make out whether two files are copied or linked in unix?

Use the long listing function of 'ls'. You will see a link count > 1 and a reference to where the file is linked to if it is a link. Without a link it is a copy.


Are the Reverse Lights on 94' Tarus linked to the Transmission?

The reverse lights on a 94' Ford Taurus are linked to the transmission to indicate when the vehicle is moving backwards. This is done for safety reasons as cars are typically moving forward.


What are the functions of enzyme linked receptors?

Most enzyme-linked receptors function as protein kinases.


Convert single linked list to double linked list?

You copy a singly linked list into a doubly linked list by iterating over the singly linked list and, for each element, calling the doubly linked list insert function.


What is the minimum number of additional pointers will be needed to reverse a singly linked list?

3 pointers...


What term is used to describe when two functions are linked together by using output of the first function as input of second function?

function composition


What is required for an individual to have a sex-linked disorder?

A sex-linked disorder is when a mutation of genes overrides the normal function of a another gene. For example, male-pattern baldness is a sex-linked disorder.


How does cellulose function in living things?

Cllulose has important function on movement of material in digestive tract


What system is the digestive system linked to?

The digestive system is linked directly to the excretory system via the liver. This organ serves an important function in both systems.


What term describes two functions linked together by using output of the first function and input of second function?

Chained or nested functions.


Which function removes last element in a list?

If you are using the doubly-linked list from the STL library, then the function call:name_of_list.push_back();should delete the last element.