Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6913233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:11:32+00:00 2026-05-27T09:11:32+00:00

The task is to reverse a linked list, so I build the linked list,

  • 0

The task is to reverse a linked list, so I build the linked list, then print is out, then all the reverse function, then print it our second time. However, the second print is empty. I think it is pointer issues here, any one can explain? thanks.

void reverseLinkedList(struct node** head) {
    struct node* curr, *prev, *temp;

    curr = *head;
    prev = NULL;

    while (curr) {
        temp = prev;
        prev = curr;        
        curr = curr->next;
        prev = temp;
    }
    *head = prev;
}

struct node* buildLinkedList(int list[], int len) {
    struct node* head = NULL;
    struct node* tail = NULL;
    struct node* node;
    int i;

    for (i = 0; i < len; i++) {
        node = (struct node*) malloc(sizeof(struct node));
        node->data = list[i];
        node->next = NULL;

        if (!head) {
            head = node;
        } else {
            tail->next = node;
        }
        tail = node;
    }
    return head;
}

void printLinkedList(struct node** head) {
    struct node* s = *head;
    while(s) {
        printf("%d\t", s->data);
        s = s->next;
    }
    printf("\n");
}

int main() {
    int list [6] = {6,7,8,3,4,5};
    struct node* header = NULL;
    header = buildLinkedList(list, 6);
    printLinkedList(&header);
    reverseLinkedList(&header);
    printLinkedList(&header);

}

The result I get from console is:

6       7       8       3       4       5   

where the second printLinkedList is printing nothing. Wondering where is the problem. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:11:33+00:00Added an answer on May 27, 2026 at 9:11 am

    Looking at your function to reverse the list you have

    while (curr) {
         temp = prev;
         prev = curr;        
         curr = curr->next;
         prev = temp;  // <<-- this resets prev to what it was before.
    }
    

    you never change the next pointer, but you change prev twice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Task: I have a camera mounted on the end of our assembly line, which
The task is to take a list of tables which is changeable. Write a
My task is to decompress a packet(received) using zlib and then use an algoritm
TASK: I'm building a set of x86 assembly reverse engineering challenges, of which I
I am trying to reverse engineer the build system of a commercial Windows based
I have some task to do, but don't know how to do it: reverse,
Recently I had a task to make a binary files parser, however it was
Task: implement paging of database records suitable for different RDBMS. Method should work for
Task at hand — I have three versions of some code, developed by different
TASK : I have an existing xml document (UTF-8) which uses xml namespaces and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.