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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:36:49+00:00 2026-05-26T18:36:49+00:00

I am trying to implement a linked list using following code, I got segment

  • 0

I am trying to implement a linked list using following code, I got segment fault error please tell me where is the problem.

I’m using ubuntu gcc compiler, please suggest me something

#include<iostream>

using  std::cout;
using  std::cin;


class ll
{
    struct node
    {
        int info;
        node *nextnode ;
    }*n;



public:
    ll()
    {
        n=NULL;
    }

    void getinfo()
    { 
        node *temp,*r;


        if( n==NULL )
        {
            temp=new node;
            cout<<" \n enter the first elements of linklist \n";
            int z;
            cin>>z;
            //i guess problem starts here
            temp->info=z;
            cout<<"the value of info is";
            temp->nextnode = NULL;
            n=temp;
        }
        else{
            temp=n;
            cout<<"heheh balls";
            while(temp->nextnode==NULL)
            {
                temp=temp->nextnode;
            }
            r=new node;
            cout<<"enter the element \t";
            int y;
            cin>>y; 
            r->info=y;
            r->nextnode=NULL;
            temp=r;
        }
    }

    void display()
    {
        node *temp=n;
        while(temp->nextnode==NULL)
        {
            cout<<temp->info;

        }
    }

};

int main()
{
    ll p;
    int v;
    cout<<"enter the number of elements to be added to linklist \t";
    cin>>v;
    //tryn to input linklist from terminal
    for(int i=0;i<v;i++)
    {
        p.getinfo();
    }
    p.display();

    return 0;
}
  • 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-26T18:36:50+00:00Added an answer on May 26, 2026 at 6:36 pm
    while(temp->nextnode==NULL)
    {
        temp=temp->nextnode;
    }
    ....
    temp=r;
    

    should be

    while(temp->nextnode!=NULL)
    {
        temp=temp->nextnode;
    }
    ....
    temp->nextnode=r;
    

    Same goes for:

    void display()
    {
        node *temp=n;
        while(temp->nextnode==NULL)
        {
            cout<<temp->info;
    
        }
    }
    

    should be:

    void display()
    {
        node *temp=n;
        while(temp!=NULL)
        {
            cout<<temp->info;
            temp = temp->nextnode;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement a linked list but get an error when compiling: intSLLst.cpp:38:
Here is code in which I am trying to implement a queue using linked
I am trying to implement a simple linked list using c++. I am probably
I am trying to implement the linked list data structure using java, it works
I am trying to implement a singly linked list in C. A common implementation
I have been trying to implement my own linked list class for didactic purposes.
I have been trying to implement XOR linked list and its operations but I
I'm making a linked list class and am trying to implement this contains() method.
I'm trying to implement a linked list in C, and I want to store
I'm trying to implement doubly-linked list in c++ and right now I'm adding iterator

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.