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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:58:32+00:00 2026-05-26T05:58:32+00:00

following linked list implementation with stacks works fine #include <iostream> using namespace std; class

  • 0

following linked list implementation with stacks works fine

#include <iostream>
using namespace std;
   class Link
   {
   public:
       long ddata;
       Link *next;
       Link(long d){
        ddata=d;

       }
        void displaylink(){
         cout<<ddata<<"  "<<endl;

        }



   };
   class LinkedList{
   private :

    Link * first;
   public:
       LinkedList(){
        first=NULL;

       }


       bool empthy(){

        return first==NULL;
       }
       void insertfirst(long dd){
        Link *newlink=new Link(dd);
        newlink->next=first;
        first=newlink;

       }
       long deletefirst(){

        Link *temp=first;
        first=first->next;
        return temp->ddata;


       }
        void display(){

         Link *current=first;
         while(current!=NULL){
             current->displaylink();
             current=current->next;

         }

          cout<<endl;
        }


   };



   class StackList{
   public:
     LinkedList *ls;
   public:
       StackList(){
           ls=new LinkedList();

       }
         void push(long j){
             ls->insertfirst(j);

         }
            long pop(){
                return   ls->deletefirst();

            }

            bool empthy()
            {
                return (ls->empthy());
            }
                void displaystack(){
                    ls->display();


                }



   };
int main(){


     StackList *SL=new StackList();
     SL->push(20);
     SL->push(40);
     SL->push(60);
     SL->displaystack();
     SL->pop();
     SL->displaystack();


 return 0;
}

but i am interested if it has some possible bugs or can it be optimized more?if you see some nonsecury point in this code please tell me how to correct it?thanks a lot,it is just curiosity question

  • 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-26T05:58:33+00:00Added an answer on May 26, 2026 at 5:58 am

    Your memory management is flawed – as is, it will leak because there are news but no deletes. Once you take care of the deletes, make sure you handle copies of the classes (have the rule of three in mind).

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

Sidebar

Related Questions

In the following program : // illustration of linked list #include <iostream> using namespace
I have the following function defined inside my linked list class. The declaration in
I'm confused by the following code: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class
For a CS class I am writing a linked list implementation of a linked
I am trying to implement a linked list using following code, I got segment
The following code is part of a stack implementation, implemented via a linked-list, in
I have the following very simplistic implementation for a single linked list in C:
I am trying to create a linked list in C++ using the following Code
I wrote a linked list implementation for my java class earlier this year. This
The following program is a basic linked list divided in 3 classes. In the

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.