0% found this document useful (0 votes)
13 views2 pages

Câu 1 Chương 4

Uploaded by

Thuan Dev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Câu 1 Chương 4

Uploaded by

Thuan Dev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Bài 1:

#include<iostream>
using namespace std;

class Node{
friend class Stack;

char _data;
Node* _pNext;
public:
Node(char data);
};
Node::Node(char data){
_data = data;
_pNext = NULL;
}

class Stack{
Node* pTop;
public:
Stack();
bool isEmpty();
void push(char data);
int peek();
void pop();
};
Stack::Stack(){
pTop = NULL;
}
bool Stack::isEmpty(){
return (pTop == NULL);
}
void Stack::push(char data){
Node* pTemp = new Node(data);
pTemp -> _pNext = pTop;
pTop = pTemp;
}
void Stack::pop(){
if(isEmpty()) return;

Node* pTemp = pTop;


pTop = pTemp->_pNext;
delete pTemp;
}
int Stack::peek(){
if(isEmpty()) return 0;
return pTop->_data;
}
void decToBinary(int n){
int binaryNum[1000];
int i = 0;
while (n > 0) {
binaryNum[i] = n % 2;
n = n / 2;
i++;
}
for (int j = i - 1; j >= 0; j--)
cout << binaryNum[j];
}
int main(){
int n;
cin>>n;
decToBinary(n);
return 0;
}

You might also like