Menu DaniWeb
Log In Sign Up
  • Read
  • Contribute
  • Meet
  1. Home
  2. Programming Forum
  3. Code Snippet Repository
  4. Reusable Code Snippet

C++ Program related question cpp file also attached

4 Years Ago Abdul_68 -1 Tallied Votes 246 Views Share

Q1. Given the partial implemenatation of Linked List, you are required to add the following functionality in the code

Delete the whole list e.g. myList.deleteAll( );
Implement Linked Stack for Character data type and show how it reverses your Name.

Q2. Show in diagramatic representation (draw by hand, take picture and paste in word) how the last node of a circular doubly linked list will be deleted, show your steps in the diagram to achieve the required task.

c++ linked-list
#include <iostream>
#include <conio.h>
using namespace std;

struct Node
{
       char data;
       Node* link;
       
};

class LinkedList
{
      private:
              Node* head;
      public:
             LinkedList()
             {
                head = NULL;
                }
           
		     void addElement(char val)
             {
                 if(head == NULL)
                 { 
                  Node* temp = new Node;
                  temp->data = val;
                  temp->link = NULL;
                  
                  head = temp;
                  temp = NULL;
                  }
                  else
                  {
                      Node* tempp = head;
                      while(tempp->link != NULL)
                          tempp = tempp->link;
                      tempp->link = new Node;
                     // Node* x = tempp->link;
                     // x->data = val;       
                     tempp->link->data = val;
                     // x->link = NULL;
                     tempp->link->link = NULL;
                  }
                  }
                  
      void display()
      {
           if(head == NULL)
             cout<<"\nList is Empty .... Nothing to Display\n";
           else
           {
               Node* temp = head;
               
               while(temp != NULL)
                  {
                    cout<<temp->data;   
                    temp = temp->link;
                    
                    }
       //             cout<<temp->data<<" ";
            }
       }   
                    
                    
void revDisplay()
      {
           if(head == NULL)
             cout<<"\nList is Empty .... Nothing Display\n";
           else
           {
               Node* temp = head;
               int count = 0;
               while(temp != NULL)
                  {
                   // cout<<temp->data;
                    temp = temp->link;
                    count++;
                    }
           // cout<<"\nLength of Name =  "<<count<<"\n";
           temp = head;         
           while(count >0){
           for(int i=1; i<count; i++)
              temp = temp->link;
              
              cout<<temp->data;
              count--;
              temp = head;
                    }   }
                    }
                    
                    };
   int main()
   {
       LinkedList myList;
       
       myList.display();
       
       //	cout<<"\nHow many Nodes do you want ";
   	//	int n;
	//   	cin>>n;
		
    	char input = ' ';
    while(input != '\r')
        {
           input = getche();
           if(input != '\r')
              myList.addElement(input);
              }
              
//       for(int i=1; i<=n; i++)
  //          myList.addElement(i);
    
       cout<<"\n\n";   
       myList.display();
       
       cout<<"\n\nName in Reverse   ";   
       myList.revDisplay();

       getch();
       
       }
Member Avatar for rproffitt Last Seen 12 Hours Ago
rproffitt 2,701 https://5calls.org Moderator
4 Years Ago

This forum rarely completes work for you. Read https://www.daniweb.com/welcome/rules but that's not entirely how these forums work.
Rarely do you find folk complete your assignment but they can help you get past a roadblock if you explain it well enough.

Here you copied the assignment and dumped code which can upset most folk I know.

Try again, make it clear where you are stuck.

Reply to this topic
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.

Sign Up — It's Free!
Related Topics
  • Member Avatar why might my program output like this? file I/O 9
  • Member Avatar File Handling+Operator Overloading 15
  • Member Avatar PHP $_GET is returning empty value if it's inside $_POST 1
  • Member Avatar C++ reading and writing to files 2
  • Member Avatar array shift to right 3
  • Member Avatar C++ Sudoku Game 15
  • Member Avatar Read This Before Posting A Question 0
  • Member Avatar C++ struct student link list 7
  • Member Avatar C++ Progamming Restaurant 2
  • Member Avatar C++, program doesn't compile, expected primary-expression, and non-pointers 0
  • Member Avatar C++ Coding for Password with requirements 1
  • Member Avatar C# scrolling game help 7
  • Member Avatar recursion call on exit 8
  • Member Avatar (C#) OpenTK adding basic shapes/textures and shaders 2
  • Member Avatar Help solving encrypted message with C++ Cipher 0
  • Member Avatar C++ to Python Conversion 1
  • Member Avatar PHP unlink(); No such file or directory 2
  • Member Avatar C++ Cylinder Code 2
  • Member Avatar Question 7
  • Member Avatar C# excel insert 2
Not what you need?

Reach out to all the awesome people in our programming community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions.

Start New Topic
Topics Feed
Reply to this Topic
Edit Preview

Share Post

Insert Code Block

  • Forums
  • Forum Index
  • Hardware/Software
    • Recommended Topics
  • Programming
    • Recommended Topics
  • Digital Media
    • Recommended Topics
  • Community Center
    • Recommended Topics
  • Latest Content
  • Newest Topics
  • Latest Topics
  • Latest Posts
  • Latest Comments
  • Top Tags
  • Topics Feed
  • Social
  • Top Members
  • Meet People
  • Community Functions
  • DaniWeb Premium
  • Newsletter Archive
  • Markdown Syntax
  • Community Rules
  • Developer APIs
  • Connect API
  • Forum API Docs
  • Tools
  • SEO Backlink Checker
  • Legal
  • Terms of Service
  • Privacy Policy
  • FAQ
  • About Us
  • Advertise
  • Contact Us
© 2025 DaniWeb® LLC