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 6327083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:12:53+00:00 2026-05-24T17:12:53+00:00

There is a singly connected linked list and a block size is given.For eg

  • 0

There is a singly connected linked list and a block size is given.For eg if my linked list is 1->2->3->4->5->6->7->8-NULL and my block size is 4 then reverse the first 4 elements and then the second 4 elements.The output of the problem should be 4->3->2->1->8->7->6->5-NULL

I was thinking of dividing the linked list into segments of size 4 and then reversing it.
But that way I am forced to use a lot of extra nodes which is not desired at all.
The space complexity should be kept to a minimum.

It will be highly appreciable if someone can come with a better solution where the usage of extra nodes would be kept to a minimum.

  • 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-24T17:12:54+00:00Added an answer on May 24, 2026 at 5:12 pm

    I tried this…seems to work fine…

    node* reverse(node* head) // function to reverse a list
    {
        node* new_head = NULL;
        while(head != NULL)
        {
            node* next = head->next;
            head->next = new_head;
            new_head = head;
            head = next;
        }
        return new_head;
    }
    
    node* reverse_by_block(node* head, int block)
    {
        if(head == NULL)
                return head;
    
        node* tmp = head;
        node* new_head = head;
        node* new_tail = NULL;
    
        int count = block;
        while(tmp != NULL && count--)
        {
            new_tail = tmp;
            tmp = tmp->next;
        }
    
        new_tail->next = NULL;
        new_tail = new_head;
        new_head = reverse(new_head);
        new_tail->next = reverse_by_block(tmp,block);
    
        return new_head;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a single algorithm that removes elements from a container as happens in
Is there a single-expression way to assign a scalar to all elements of a
There are many basic graph algorithms such as topological sort, strongly/weakly connected components, all-pairs/single-source
I'm using dojo's DateTextBox with a connected onChange event. There are cases users select
Is there a single shortcut to start inserting in the new line at end
Is there a single preprocessor token that can be used to detect any iPhone
Is there a single query (subqueries in it are allowed) where I can copy
I have a web scraping application, written in OO Perl. There's single WWW::Mechanize object
By default there is a single line separator in uitableview. But I want to
I see in richfaces that there is a single slider, wondering if anyone has

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.