class A {
public:
void show() {
cout << "Base Class\n";
} };
class B : virtual public A {};
class C : virtual public B {};
class D : public B, public C {};
-> use virtual in base class inheritance to avoid diamond problem.
class A {
public:
void show() {
cout << "Base Class\n";
} };
class B : virtual public A {};
class C : virtual public B {};
class D : public B, public C {};
-> use virtual in base class inheritance to avoid diamond problem.
int isFull(Node* top) {
Node* p = new(nothrow) Node; // Safe allocation prevents bad_alloc, include new
if(!p) {
return 1;
} else {
delete p;
return 0;
}
}
Node* push(Node* top, int x) {
Node* n = new Node; // Memory allocation
if (!n) { // or (n == NULL)
cout << "Stack overflow" << endl;
return top;
}
n->data = x;
n->next = top;
top = n;
return top;
}
int pop() {
if(isEmpty(top))
{
cout << "Stack underflow << endl;
return -1;
}
else
{
Node* n = top;
int x = n->data;
top=top->next;
free(n);
return x;
}
}
void linkedListTraversal(Node* ptr) {
while (ptr != NULL) {
cout << " Element : " << ptr->data << endl;
ptr = ptr->next;
}
}
It travels across the LinkedList and prints all the elements.
Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...