Huawei machine questions -- reverse order of single-chain table

Source: Internet
Author: User

Huawei machine questions -- reverse order of single-chain table
[Problem]

Reverse Sequence of a single-chain table

[Code]

# Include
 
  
# Include
  
   
# Include
   
    
Typedef struct ListNode {int value; struct ListNode * next;} ListNode; typedef struct ListNode * List; List reverseList (List head) // List reverse {ListNode * rear, * curr, * front; rear = curr = head; while (curr! = NULL) {front = curr-> next; curr-> next = rear; rear = curr; curr = front;} head-> next = NULL; head = rear; return head;} List createdList (int a [], int len) // create a List {int I = 1; ListNode * head, * curr, * rear; curr = (ListNode *) malloc (sizeof (ListNode); curr-> value = a [0]; curr-> next = NULL; head = rear = curr; while (I <len) {curr = (ListNode *) malloc (sizeof (ListNode); curr-> value = a [I ++]; curr-> next = NULL; Rear-> next = curr; rear = curr;} return head;} void printList (List head) // print the List {ListNode * curr; curr = head; while (curr! = NULL) {printf ("% d", curr-> value); curr = curr-> next ;}} int main (void) {int a [5] = {1, 2, 3, 4, 5}; List head; head = createdList (a, 5); head = reverseList (head ); printList (head); printf ("\ n"); return 0 ;}
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.