You don't need to tick the "Request desktop site" option in your browser anymore while using a mobile device, but if you don't then the code formatting of the code given as text for copying will be disturbed.
Code:
[Now VERIFIED]
{100% working.}
If you know how to copy paste on skillrack then you can copy the code from below:
template<class T>
AC_BinaryTree<T>::AC_BinaryTree(){no_Of_Ele=0;capacity=20; ele=new T[20];}
template<class T> bool AC_BinaryTree<T>::isEmpty(){return !no_Of_Ele;}
template<class T> bool AC_BinaryTree<T>::isFull(){return (no_Of_Ele==20);}
template<class T> void AC_BinaryTree<T>::insert(T x){
if (isFull()) {cout<<"Tree full insertion cannot be made\n";return;}
ele[no_Of_Ele++]=x;
} //jugaadu-skillrack.blogspot.in
template<class T> T AC_BinaryTree<T>::leftChild(int x){
if(2*x+1<no_Of_Ele) {ERR_Flag=false; return ele[2*x+1];}
cout<<"No left child\n"; ERR_Flag=true; return ele[0];
}
template<class T> T AC_BinaryTree<T>::rightChild(int x){
if(2*x+2<no_Of_Ele) {ERR_Flag=false; return ele[2*x+2];}
cout<<"No right child\n"; ERR_Flag=true; return ele[0];
}
template<class T> T AC_BinaryTree<T>::parent(int x){return ele[(x-1)/2];}
AC_BinaryTree<T>::AC_BinaryTree(){no_Of_Ele=0;capacity=20; ele=new T[20];}
template<class T> bool AC_BinaryTree<T>::isEmpty(){return !no_Of_Ele;}
template<class T> bool AC_BinaryTree<T>::isFull(){return (no_Of_Ele==20);}
template<class T> void AC_BinaryTree<T>::insert(T x){
if (isFull()) {cout<<"Tree full insertion cannot be made\n";return;}
ele[no_Of_Ele++]=x;
} //jugaadu-skillrack.blogspot.in
template<class T> T AC_BinaryTree<T>::leftChild(int x){
if(2*x+1<no_Of_Ele) {ERR_Flag=false; return ele[2*x+1];}
cout<<"No left child\n"; ERR_Flag=true; return ele[0];
}
template<class T> T AC_BinaryTree<T>::rightChild(int x){
if(2*x+2<no_Of_Ele) {ERR_Flag=false; return ele[2*x+2];}
cout<<"No right child\n"; ERR_Flag=true; return ele[0];
}
template<class T> T AC_BinaryTree<T>::parent(int x){return ele[(x-1)/2];}
Input:
Choice for type of element (1,2)Choice for operation in tree (1,2,3,4,5,6,7)
if choice of operation =3 then: Element to be inserted
Output:
For options 1 and 2 'Empty' or 'Not empty', 'Full' or 'Not full' appropriately
value of leftchild / rightchild / parent when option is chosen and 'No left child' or 'No right child' when applicable
Processing:
left child of ele[x] is given by ele[x*2 +1]
right child of ele[x] is given by ele[x*2 +2]
parent of ele[x] is given by ele[(x-1)/2]
Psuedocode:
start
let num=0, cap=20.
while (true)
input choice
if choice=1
if num=0 output "Empty"
else output "Not Empty"
if choice=2
if num=cap output "Full"
else output "Not Full"
if choice=3
if num<=cap input ele[num] and let num=num+1
else output "Tree full insertion cannot be made"
if choice=4
input x
if (2*x+1<num) output ele[2*x+1]
else output "No left child"
if choice=5
input x
if (2*x+2<num) output ele[2*x+2]
else output "No right child"
if choice=6
input x
output ele[(x-1)/2]
if choice=7
goto end of while
end if
end while
stop
No comments:
Post a Comment