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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:38:48+00:00 2026-06-15T02:38:48+00:00

I am working on a piece of C# code that is adding digits that

  • 0

I am working on a piece of C# code that is adding digits that are stored in singly linked list. I have created a buffer singly linked list that contains 11 11 8 . the final list has to look like 1 2 9 . Each element that is bigger than 10 has to pass a carry over to the next digit and the result of the %10 is passed to the final list that will create 1 2 9.
How can I handle the carry over from each digit starting on the left to the right?

I have created the following logic, but obviously I am ignoring something.

 for (int i = 0; i < bufferList.Size(); i++)
 {
     int mostLeftValue = Convert.ToInt32(bufferList.GetValue(i));
     if (mostLeftValue >=10  && i + 1 < bufferList.Size())
     {
         int nextLeftValue = Convert.ToInt32(bufferList.GetValue(i + 1))+1;
         int modedNextValue = nextLeftValue % 10;
         finalList.InsertAtTail(modedNextValue);           
     }

     int moddedValue =  mostLeftValue %10 ;
     finalList.InsertAtFront(moddedValue);
  • 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-06-15T02:38:49+00:00Added an answer on June 15, 2026 at 2:38 am

    It doesn’t look like you’re carrying anything over from one value to the next. Also, you’re adding to both ends of the output list, which seems suspect.

    Here’s an implementation for a simple List<int> – it basically does what you do when you add two numbers by hand, just without actually adding. Take the current number, add the carried number, store the “units”, carry the “tens” over to the next column.

    Number      11   11    8
    Carry        0 ┌─ 1 ┌─ 1 ┌─ 0
    Sum         11 │ 12 │  9 │
    Store        1 │  2 │  9 │  stop
    Carry over  1 ─┘ 1 ─┘ 0 ─┘
    

    You should be able to modify it for a linked list ([i] -> .GetValue(i), .Add -> .InsertAtTail, .Count -> .Size() or similar):

    int carry = 0;
    for (int i = 0; i < input.Count; i++)
    {
        int sum = carry + input[i]; // add previous carry
        output.Add(sum % 10);       // store the "units"
        carry = sum / 10;           // carry the "tens"
    }
    while (carry > 0)               // anything left carried?
    {
        output.Add(carry % 10);     // store the "units"
        carry = carry / 10;         // carry the "tens"
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a piece of code that I am working on using function
I have this piece of code that is working fine in python 2.7. dist
I'm just learning Android. I have working piece of code that uses ContentValues: My
I have this piece of code that is working but is kind of cumbersome.
I'm working on a piece of code that I inherited and am trying to
I'm working on a piece of code that GETs a URL and parses the
I am working on a piece of code that writes data from 4 different
I'm currently working on a piece of code that quite simply uses a boolean
I'm working on a piece of code that interacts with Resources (Executables) however i'm
I am currently working on the maintenance of a piece of code that is

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.