How do you write a function that can reverse a linked-list?

1 Answer

Answer :

if(head==0)
return;
if(head->next==0)
return;
if(head->next==tail)
{
head->next = 0;
tail->next = head;
}
else
{
node* pre = head;
node* cur = head->next;
node* curnext = cur->next;
head->next = 0;
cur-> next = head;
for(; curnext!=0; )
{
cur->next = pre;
pre = cur;
cur = curnext;
curnext = curnext->next;
}
curnext->next = cur;
}
}

Related questions

Description : A system wherein items are added from one and removed from the other end. a) Stack b) Queue c) Linked List d) Array

Last Answer : Answer: b Explanation: In a queue, the items are inserted from the rear end and deleted from the front end

Description : Tell how to check whether a linked list is circular.

Last Answer : Create two pointers, each set to the start of the list. Update each as follows: while (pointer1) { pointer1 = pointer1->next; pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next; if (pointer1 == pointer2) { print (\"circular\n\"); }

Description : How do you find out if a linked-list has an end? (i.e. the list is not a cycle)

Last Answer : You can find out by using 2 pointers. One of them goes 2 nodes each time. The second one goes at 1 nodes each time. If there is a cycle, the one that goes 2 nodes each time will eventually meet the one that goes slower. If that is the case, then you will know the linked list is a cycle.

Description : Write a program to reverse the number 1234 (i.e. 4321) using function. 

Last Answer : #include #include void findReverse(); void main() { findReverse(); } void findReverse() {  int num, res=0,ans=0; clrscr(); printf("Enter the number"); scanf("%d", &num); while(num!=0) { res=num%10; ans=ans*10+res; num=num/10; } printf("Reverse number is %d", ans); getch(); }

Description : Are the amount of chemicals in the food you eat (or don't eat) an issue to you (for example the McDonald's McRib Sandwich ingredient list, articles linked here)?

Last Answer : No. And the photo is just what meat looks like when it's flash frozen. Any meat will look like that. The fact that it's been chopped and pressed into that shape isn't particularly appealing to ... we do it with hamburgers too. Past too. Wendy's presses their hamburger into squares or they used to.

Description : Is it possible to return an entire linked list object from a method in C++ without running the destructor?

Last Answer : Your description in the problem doesn't really describe what you want it to do that you would call right, nor does it explain how it uses its linked list. If you haven't figured out exactly what you want ... want to do that you can describe clearly, then yes, there will be a right way to do it.

Description : Which is/are correctly linked here? `{:(,"List I",,"List II"),((a),E_(1)Cb,(a),"Carbanion formation"),((b),E_(2),(b),"Stereo specific"),((c),S_(N^(1))

Last Answer : Which is/are correctly linked here? `{:(,"List I",,"List II"),((a),E_(1)Cb,(a),"Carbanion formation" ... "),((d),E_(1),(d),"Carbocation formation"):}`

Description : Define what is linked list?

Last Answer : A linked list is composed of nodes that are connected with another. In C programming, linked lists are created using pointers. Using linked lists is one efficient way of utilizing memory for storage.

Description : Linked Lists -- Can you tell me how to check whether a linked list is circular?

Last Answer : Create two pointers, and set both to the start of the list. Update each as follows: while (pointer1) { pointer1 = pointer1->next; pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next ... before pointer1, or the item before that. Either way, its either 1 or 2 jumps until they meet.

Description : Which of the following statement is true? i) Using singly linked lists and circular list, it is not possible to traverse the list backwards. ii) To find the predecessor, it is required to traverse the list from the first ... linked list. A) i-only B) ii-only C) Both i and ii D) None of both

Last Answer : C) Both i and ii

Description : Suppose you want to delete the name that occurs before “Vivek” in an alphabetical listing. Which of the following data structures shall be most efficient for this operation? (A) Circular linked list (B) Doubly linked list (C) Linked list (D) Dequeue

Last Answer :  (B) Doubly linked list 

Description : If the queue is implemented with a linked list, keeping track of a front pointer and a rear pointer, which of these pointers will change during an insertion into a non-empty queue? (A) Neither of ... (B) Only front pointer changes (C) Only rear pointer changes (D) Both of the pointers changes

Last Answer : (C) Only rear pointer changes

Description : Consider an implementation of unsorted single linked list. Suppose it has its representation with a head and a tail pointer (i.e. pointers to the first and last nodes of the linked list). Given the ... the front node of the linked list. (D) Deletion of the last node of the linked list.

Last Answer : (D) Deletion of the last node of the linked list. 

Description : Different components of the motherboard of a PC unit are linked together by sets of parallel electrical conducting lines. What are these lines called? A) Conductors B) Buses C) Connectors D) Consecutives

Last Answer : Answer : B

Description : What’s on your reverse bucket list - what would you NEVER do again?

Last Answer : Trust someone with my personal thoughts and feelings, just shallow relationships from now on.

Description : What’s on your reverse bucket list - what would you NEVER do again?

Last Answer : Trust someone with my personal thoughts and feelings, just shallow relationships from now on.

Description : 10.) A two-digit number is prime. When you reverse the digits, that number is also prime. What could the number be List three possibilities.?

Last Answer : Some numbers that you can get when you reverse the digits and they are still prime numbers are: 403 ÷ 13 = 31 2,701 ÷ 37 = 73 1,207 ÷ 17 = 71

Description : 10.) A two-digit number is prime. When you reverse the digits, that number is also prime. What could the number be List three possibilities.?

Last Answer : Some numbers that you can get when you reverse the digits and they are still prime numbers are: 403 ÷ 13 = 31 2,701 ÷ 37 = 73 1,207 ÷ 17 = 71

Description : ………… is very useful in situation when data have to stored and then retrieved in reverse order. A) Stack B) Queue C) List D) Link list

Last Answer : A) Stack

Description : What is the name of the display feature that highlights are of the screen which requires operator attention? A) Pixel B) Reverse video C) Touch screen D) Cursor

Last Answer : Answer : B

Description : RISC stands for________ A. Reverse Instruction Set Computer B. Reverse Information Set Computer C. Reduced Information Set Computer D. Reduced Instruction Set Computer

Last Answer : D. Reduced Instruction Set Computer

Description : A legal agreement between the lender and borrower where real estate property is used as a collateral for the loan is termed as ________ A. Mortgage B. Reverse Mortgage C. Repossession D. Refinance

Last Answer : A. Mortgage Explanation: A loan that is secured by property or real estate is called a mortgage. In exchange for funds received by the homebuyer to buy property or a home, a lender gets the promise of that buyer to pay back the funds within a certain time frame for a certain cost.

Description : A financial product which provides senior citizens with funds against their home equity is referred as _______ A. Mortgage B. Reverse Mortgage C. Repossession D. Refinance

Last Answer : B. Reverse Mortgage Explanation: A reverse mortgage or home equity conversion mortgage (HECM) is a special type of home loan for older home owners (62 years or older) that requires no monthly mortgage payments. Borrowers are still responsible for property taxes and home owner‘s insurance.

Description : Which of the following is governed by the provisions of Section 42 of the Reserve Bank of India Act, 1934? A. Bank rate B. Reverse Repo Rate C. SLR D. CRR E. None of the Above

Last Answer : D. CRR Explanation: CRR is governed by the provisions of Section 42 of the Reserve Bank of India Act, 1934. There is no minimum & maximum level of CRR. We could go upto zero CRR (negative values are of course absurd).

Description : The following protocols and system are commonly used to provide various degrees of security services in computer network. i) IP filtering ii) Reverse Address Translation iii) IP security Architecture (IPsec) iv) Firewalls v) Socks A) ... v only C) ii, iii, iv and v only D) All i, ii, iii, iv and v

Last Answer : B) i, iii, iv and v only

Description : ........... is responsible for converting the higher level protocol addresses to physical Network Addresses. A) Address Resolution Protocol (ARP) B) Reverse Address Resolution Protocol (RARP) C) Bootstrap Protocol (BOOTP) D) Internet Control Message Protocol (ICMP)

Last Answer : A) Address Resolution Protocol (ARP)

Description : Reverse T3 is (A) A synthetic compound given counter the effects of T3 (B) Formed from T4 but has no hormone function (C) Formed by isomerisation of T3 (D) Formed from T4 and has hormone function

Last Answer : Answer : B

Description : The function of the commutator in a DC motor is to ________. A. reverse the flow of current through the armature B. reverse the flow of current in the field poles C. reduce the reluctance of the magnetic path through the motor D. shift the neutral running plane of the brushes to prevent sparking

Last Answer : Answer: A

Description : A signal derived from a controlled function and returned to the initiating point is called a/an ____________. A. monitoring signal B. inverse signal C. reverse signal D. feedback signal

Last Answer : Answer: D

Description : Write a program which concate and reverse string by using pointer to string.

Last Answer : #include #include void main()  { char str1[20], str2[20], rev[20],*p1,*p2; int cnt=0; clrscr(); coutstr2;  p1=&str1[0];  p2=&str2[0]; while(*p1!='\0')  { p1++;  } while(*p2!='\0')  { *p1=*p2; p1++; p2++;  }  *p1='\0'; cout

Description : Write a program in C++ to accept a string from a user and display its reverse using pointer.

Last Answer : #include<iostream.h> #include<conio.h> #include<string.h> void main() { char str[20],*ptr; int l; clrscr(); cout<<"\n Enter a string : "; cin>>str; l=strlen(str); ... (l!=0) { ptr--; cout<<*ptr; l--; } getch(); }