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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:40:18+00:00 2026-05-14T01:40:18+00:00

thanks for taking the time to stop by my question. Below you will find

  • 0

thanks for taking the time to stop by my question.

Below you will find my working SLL, but I want to make more use of C# and, instead of having two classes, SLL and Node, I want to use Node’s constructors to do all the work (To where if you pass a string through the node, the constructor will chop it up into char nodes). The problem is, after an a few hours of tinkering, I’m not really getting anywhere…

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace PalindromeTester
{
    class Program
    {
        static void Main(string[] args)
        {
            SLL mySLL = new SLL();
            mySLL.add('a');
            mySLL.add('b');
            mySLL.add('c');
            mySLL.add('d');
            mySLL.add('e');
            mySLL.add('f');

            Console.Out.WriteLine("Node count = " + mySLL.count);
            mySLL.reverse();
            mySLL.traverse();
            Console.Out.WriteLine("\n The header is: " + mySLL.gethead);
            Console.In.ReadLine();
        }

        class Node
        {
            private char letter;
            private Node next;

            public Node()
            {
                next = null;
            }

            public Node(char c)
            {
                this.data = c;
            }

            public Node(string s)
            {

            }

            public char data
            {
                get { return letter; }
                set { letter = value; }
            }

            public Node nextNode
            {
                get { return next; }
                set { next = value; }
            }
        }

        class SLL
        {
            private Node head;
            private int totalNode;

            public SLL()
            {
                head = null;
                totalNode = 0;
            }

            public void add(char s)
            {
                if (head == null)
                {
                    head = new Node();
                    head.data = s;

                }
                else
                {
                    Node temp;
                    temp = new Node();
                    temp.data = s;
                    temp.nextNode = head;
                    head = temp;
                }
                totalNode++;
            }

            public int count
            {
                get { return totalNode; }
            }

            public char gethead
            {
                get { return head.data; }
            }

            public void traverse()
            {
                Node temp = head;
                while(temp != null)
                {
                    Console.Write(temp.data + " ");
                    temp = temp.nextNode;
                }
            }

            public void reverse()
            {
                Node q = null;
                Node p = this.head;
                while(p!=null)
                {
                    Node r=p;
                    p=p.nextNode;
                    r.nextNode=q;
                    q=r;
                }
                this.head = q;
            }
        }
    }
}

Here’s what I have so far in trying to work it into Node’s constructors:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace PalindromeTester
{
    class Program
    {
        static void Main(string[] args)
        {

            Node myNode = new Node("hello");

            Console.Out.WriteLine(myNode.count);
            myNode.reverse();
            myNode.traverse();
            Console.In.ReadLine();
        }

        class Node
        {
            private char letter;
            private Node next;
            private Node head;
            private int totalNode;

            public Node()
            {
                head = null;
                totalNode = 0;
            }

            public Node(char c)
            {
                if (head == null)
                {
                    head = new Node();
                    head.data = c;

                }
                else
                {
                    Node temp;
                    temp = new Node();
                    temp.data = c;
                    temp.nextNode = head;
                    head = temp;
                }
                totalNode++;
            }

            public Node(string s)
            {
                foreach (char x in s)
                {
                    new Node(x);
                }
            }

            public char data
            {
                get { return letter; }
                set { letter = value; }
            }

            public Node nextNode
            {
                get { return next; }
                set { next = value; }
            }

            public void reverse()
            {
                Node q = null;
                Node p = this.head;
                while (p != null)
                {
                    Node r = p;
                    p = p.nextNode;
                    r.nextNode = q;
                    q = r;
                }
                this.head = q;
            }

            public void traverse()
            {
                Node temp = head;
                while (temp != null)
                {
                    Console.Write(temp.data + " ");
                    temp = temp.nextNode;
                }
            }

            public int count
            {
                get { return totalNode; }
            }
        }
    }
}

Ideally, the only constructors and methods I would be left with are Node(), Node(char c), Node(string s), Node reserve() and I’ll be reworking traverse into a ToString overload.

Any suggestions?

  • 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-14T01:40:18+00:00Added an answer on May 14, 2026 at 1:40 am

    If you want your linked list to be able to chop up a string into several nodes, then make sure the method to do so is actually contained on the LL and not on the node object. In theory you’re never supposed to know about the node object unless you’re looking for the next/previous value.

    Your char-linked-list should have two methods: One to add a char, and one to add a string that will be chopped up into several nodes. The node object itself should only have a single constructor that takes a char.

    Basically trying to rewrite the data structure to only consist of a single class is a really bad idea. You really need at least two objects. One to keep track of the nodes, and a node object to be kept track of.

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

Sidebar

Related Questions

Thanks for taking the time to answer my question. I want to check if
first of all thanks for taking your time! I'm a junior Dev, working with
Thanks for taking time to read this question. I am designing a 3-tier solution
First off good day and thanks for taking the time to answer my question.
First of all, thanks for taking the time to read my question, I appreciate
thanks for the taking the time to read my question. I'm pulling information for
Thanks for taking the time to read my question. I am looking for advice
Thanks for taking the time to read... here is my question/scenario, its a quick
First of all, thanks for taking the time to read this. I've been working
Thanks for taking time to review this question. I've been trying to fix a

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.