BITP Data Structures and Algorithm, Study notes of Data Structures and Algorithms

This is my BITP project that I have done. Hopefully it will help other students

Typology: Study notes

2019/2020

Uploaded on 10/09/2021

Syazzz
Syazzz 🇲🇾

4 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PROGRAM EXAMPLE 1
// Example_1.cpp
#include <iostream>
using namespace std;
template <class T>
void Change(T x, T y)
{
cout << "Before Change: first value: " << x
<< "\n\t\tsecond value: " << y << endl << endl;
T a;
a = x;
x = y;
y = a;
cout << "After change: first value: " << x
<< "\n\t\tsecond value: " << y << endl << endl;
}
void main()
{
Change('s', 'k');
Change(90, 2);
}
pf3

Partial preview of the text

Download BITP Data Structures and Algorithm and more Study notes Data Structures and Algorithms in PDF only on Docsity!

PROGRAM EXAMPLE 1

// Example_1.cpp #include using namespace std; template void Change(T x, T y) { cout << "Before Change: first value: " << x << "\n\t\tsecond value: " << y << endl << endl; T a; a = x; x = y; y = a; cout << "After change: first value: " << x << "\n\t\tsecond value: " << y << endl << endl; } void main() { Change('s', 'k'); Change(90, 2); }

PROGRAM EXAMPLE 2

// Change.h #ifndef CHANGE_H #define CHANGE_H template class Change { private: T first, second; public: Change(); ~Change(); void setValue(T, T); void toChange(); }; #endif template Change::Change() {} template Change::~Change() {} template void Change::setValue(T x, T y) { first = x; second = y; } template void Change::toChange() { cout << "After Change: first value: " << first << "\n\t\tsecond value: " << second << endl << endl; T a; a = first; first = second; second = a; cout << "After Change: first value: " << first << "\n\t\tsecond value: " << second << endl << endl; } // Example_2.cpp #include using namespace std; #include "Change.h" void main() { Change a; Change b; a.setValue('s', 'k'); a.toChange(); b.setValue(90, 2); b.toChange(); }