shailendra.rajput
BAN USER- 0of 0 votes
Answers2> write program to mirror the binary tree.
- shailendra.rajput in India| Report Duplicate | Flag | PURGE
Salesforce Developer Program Engineer Algorithm - 0of 0 votes
Answersclass template vs template class?
- shailendra.rajput in India
c++ specific properties?
struct vs class?
encapsulation vs abstraction?
Design a holder - bulbs(LED,Normal,Tube light) - uml relation ship?
multiple inheritance, multiple level inheritance-CTOR and DTOR order for base classes ?
why use templates?
what is abstract class?
unit testing tools used?
smart poiner vs dangling pointer
why we take "Base& obj" as input in Base Copy CTOR function, in Base(Base& obj){}, why not "Base obj".
shallow copy vs Deep copy.| Report Duplicate | Flag | PURGE
Dover Organization Dev Lead Dev Lead C++
#include <iostream>
using namespace std;
struct Node
{
int mData;
Node* mNext;
Node(int data , Node* next=nullptr):mData(data),mNext(next) {}
};
struct List
{
List():mHead(nullptr){}
Node* mHead;
void Add(int data)
{
if(!mHead)
mHead = new Node(data);
else
{
Node* temp = mHead;
while(temp->mNext != nullptr)
temp = temp->mNext;
temp->mNext = new Node(data);
}
}
void Display()
{
Node *temp = mHead;
cout<<"\n Content of List are : ";
while(temp != nullptr)
{
cout<<"\t"<<temp->mData;
temp = temp->mNext;
}
}
void Find_Last_nth_Element(int count)
{
if( (count>0) && mHead)
{
Node* temp = mHead;
int index = 0;
while( (index < count) && temp )
{
temp = temp->mNext;
++index;
}
if(index != count)
cout<<"\n lesser elements in List"<<endl;
else
{
Node* nthNode = mHead;
while(temp)
{
temp = temp->mNext;
nthNode = nthNode->mNext;
}
cout<<"\n the "<<count<<" node from last in list is "<<nthNode->mData;
}
}
}
};
void main()
{
cout<<"\n Program Started"<<endl;
List myList;
for(int i=0;i<20;++i)
myList.Add(10*i+i);
myList.Display();
int nthNode=0;
cout<<"\nEnter nth Element from last:";
cin>>nthNode;
myList.Find_Last_nth_Element(nthNode);
cout<<"\n Program Ended"<<endl;
}
#include <iostream>
- shailendra.rajput November 05, 2014using namespace std;
struct Node
{
int mData;
Node* mNext;
Node(int data , Node* next=nullptr):mData(data),mNext(next) {}
};
struct List
{
List():mHead(nullptr){}
Node* mHead;
void Add(int data)
{
if(!mHead)
mHead = new Node(data);
else
{
Node* temp = mHead;
while(temp->mNext != nullptr)
temp = temp->mNext;
temp->mNext = new Node(data);
}
}
void Display()
{
Node *temp = mHead;
cout<<"\n Content of List are : ";
while(temp != nullptr)
{
cout<<"\t"<<temp->mData;
temp = temp->mNext;
}
}
void Find_Last_nth_Element(int count)
{
if( (count>0) && mHead)
{
Node* temp = mHead;
int index = 0;
while( (index < count) && temp )
{
temp = temp->mNext;
++index;
}
if(index != count)
cout<<"\n lesser elements in List"<<endl;
else
{
Node* nthNode = mHead;
while(temp)
{
temp = temp->mNext;
nthNode = nthNode->mNext;
}
cout<<"\n the "<<count<<" node from last in list is "<<nthNode->mData;
}
}
}
};
void main()
{
cout<<"\n Program Started"<<endl;
List myList;
for(int i=0;i<20;++i)
myList.Add(10*i+i);
myList.Display();
int nthNode=0;
cout<<"\nEnter nth Element from last:";
cin>>nthNode;
myList.Find_Last_nth_Element(nthNode);
cout<<"\n Program Ended"<<endl;
}