Tuesday, 9 April 2013
Double link list with template
#define __PS_DLL_H_
#include <iostream>
using namespace std;
template <class T>
class DLL;
template <class T>
class Node{
T _data;
Node<T>* _prev;
Node<T>* _next;
Node(T data, Node<T>* prev=(Node<T>*)0, Node<T>* next=(Node<T>*)0);// just incase, review later
friend class DLL<T>;
};
template <class T>
class DLL{
Node<T>* _head;
Node<T>* _curr;
Node<T>* _tail;
void copy(DLL<T>& D);
public:
DLL();
DLL(DLL<T>& D);
virtual ~DLL();
bool isEmpty();
void append(T data);
DLL<T>& operator=(DLL<T>& D);
T remove(); // removes the current node and returns the data
bool del(); // removes the current node returns false if is empty
void insert(T data); // insterts before current
bool goHead();
bool goTail();
bool goNext();
bool goPrev();
T visit(); // returns the current data
int dept() const; // returns the number of Nodes
};
template <class T>
Node<T>::Node(T data, Node<T>* prev, Node<T>* next){
_data = data;
_prev = prev;
_next = next;
}
template <class T>
DLL<T>::DLL(){
_head = _tail = _curr = 0;
}
template <class T>
DLL<T>::~DLL(){
while(del());
}
template <class T>
void DLL<T>::copy(DLL<T>& D){
int curpos;
for(curpos=0;D.goPrev();curpos++); // findout where is current
if(!D.isEmpty()){
do{
this->append(D.visit());
}while(D.goNext());
}
for(D.goHead(), this->goHead(); curpos; D.goNext(), this->goNext(),curpos--);
}
template <class T>
DLL<T>::DLL(DLL<T>& D){
_head = _tail = _curr = 0;
this->copy(D);
}
template <class T>
DLL<T>& DLL<T>::operator=(DLL<T>& D){
while(del());
this->copy(D);
return *this;
}
template <class T>
void DLL<T>::append(T data){
Node<T>* newnode = new Node<T>(data);
if(_tail){ // ! empty
_tail->_next = newnode;
newnode->_prev = _tail;
_tail = _curr = newnode;
}
else{
_tail = _curr = _head = newnode;
}
}
template <class T>
T DLL<T>::remove(){
T data = visit();
del();
return data;
}
template <class T>
bool DLL<T>::del(){
bool ok = false;
if(_curr){
ok = true;
Node<T>* todel = _curr;
(_curr->_next) ? _curr->_next->_prev = _curr->_prev : _tail = _tail->_prev;
(_curr->_prev) ? _curr->_prev->_next = _curr->_next : _head = _head->_next;
(_curr->_next) ? _curr = _curr->_next : _curr = _curr->_prev;
delete todel;
}
return ok;
}
template <class T>
void DLL<T>::insert(T data){
Node<T>* toInsert = new Node<T>(data);
(_curr->_prev) ? (_curr->_prev->_next = toInsert) : (_head = toInsert);
toInsert->_prev = _curr->_prev;
toInsert->_next = _curr;
_curr->_prev = toInsert;
_curr = toInsert;
}
template <class T>
T DLL<T>::visit(){ // retruns data of current
return _curr->_data;
}
template <class T>
bool DLL<T>::goHead(){
return ((_head) && (_curr = _head)) ? true : false;
}
template <class T>
bool DLL<T>::goTail(){
return ((_tail) && (_curr = _tail)) ? true : false;
}
template <class T>
bool DLL<T>::goNext(){
return ((_curr->_next) && (_curr = _curr->_next)) ? true : false;
}
template <class T>
bool DLL<T>::goPrev(){
return ((_curr->_prev) && (_curr = _curr->_prev)) ? true : false;
}
template <class T>
bool DLL<T>::isEmpty(){
return !_curr;
}
template <class T>
void printList(DLL<T>& d){
d.goHead();
}
template <class T>
ostream& operator<<(ostream& os, DLL<T>& d){
int cur;
bool done = false;
for(cur=0;d.goPrev();cur++); // findout where is current
do{
os<<d.visit();
done = !d.goNext();
if(!done){
os<<", ";
}
}while(!done);
for(d.goHead();cur;d.goNext(), cur--); // set current to what it was before
return os;
}
template <class T>
ostream& operator>>(ostream& os, DLL<T>& d){ // printing in reverse!!!!!
int cur;
bool done = false;
for(cur=0;d.goNext();cur++); // findout where is current
do{
os<<d.visit();
done = !d.goPrev();
if(!done){
os<<", ";
}
}while(!done);
for(d.goTail();cur;d.goPrev(), cur--); // set current to what it was before
return os;
}
#endif
#include "dll.h"
int main(){
DLL<int> d;
for(int i=0;i<10;i++){
d.append(i+1);
}
cout<<d<<endl;
d.goHead();
d.insert(1000);
d.goNext();
d.insert(2000);
cout<<d<<endl;
cout>>d<<endl;
cout<<d.remove()<<endl;
cout<<d<<endl;
return 0;
}
Saturday, 30 March 2013
Problem in project .exe file
Everything is working perfectly but do not know this project.exe is giving me error. I tried to build new projects but still having same problem. Such a crazy headache......... :(
Monday, 25 March 2013
CDirection issue Solved
Hi friends
Sorry for CDirection issue. I did something wrong. Actually I forgot to use namespace. That's why I was getting error. Anyways it is solved.
Thank you
Pankaj Sama
Thursday, 21 March 2013
Getting CDirection Error
I am doing my CMenuItem. I updated the cuigh.h as on wiki page but I am getting an error "Cdirection is not defined" in Cframe.h. But it is prototype in cuigh.h as
"enum CDirection {centre, left, right, up, down};
Can somebody help me with that. Looking forward for reply
Thanks
Pankaj Sama
Wednesday, 20 March 2013
Convert Bits value of a variable(any type) to Hex
#include <iostream>
using namespace std;
void bitDump(void* address, unsigned int size);
int main(){
long double ld = 12345.123456;
bitDump(&ld, sizeof(ld)); // print the bit pattern (cool if formatted)
return 0;
}
//Loop through size and convert each char to 8 binary digits.
void bitDump(void* var, unsigned int size){
char* addres = (char*) var;
int count = 1;
for(int i = 0; i < sizeof(size); i++){
unsigned int mask = 1 << 7;
while(m){//convert each char to 8 binary digits
printf("%d", !!(addres[i] & mask));
m = m >> 1;
if(count == 4)
{
putchar(' ');
cnt = 1;
}
else
{
count++;
}
}
putchar('\n');
}
BitPrint Function
Function to Print the Bits of a variable.....
void prnBits(unsigned int val)
{
unsigned int m = 1 << sizeof(val)*8 - 1;
while(m)
{
printf("%d\n", (val & m) && 1);
m = m >> 1;
}
}
SetBits Function
void setBits(unsigned int&, int BitNo, bool value)
{
if(value)
{
v = v | (1 << (BitNo - 1));
}
else
{
v = v & ~(1 << (BitNo - 1));
}
}
Wednesday, 13 March 2013
Update cuigh.h and frame.h
I update the cuigh.h and frame.h in the master and did pull request. Please have a look on code and let me know about if it has any problem.
Regards
Pankaj Sama
Tuesday, 5 March 2013
C_BUTTON_HIT key
As given information in the CButton Implementation specification. The C_BUTTON_HIT Key is not defined in "cuigh.h" class. Can anybody let me know about this issue.
Thanks
Pankaj Sama
Thursday, 14 February 2013
0.2 Milestone
Done with Mock up classes and wiki team page. Learn new things like compilation of program without having code. Which is good for coming future in programming. :)
Monday, 11 February 2013
Tuesday, 5 February 2013
OOP344 Project 0.1 Completed
//Cheers
Project 0.1
Having trouble with ptoject while compling.....i do not know what is going on....having stupid kinds of errors....
Wednesday, 30 January 2013
END Key
Working on END key...but having lot of trouble with coding...but still trying to complete it as soon as possible....
Sunday, 27 January 2013
OOP344 Week 3 to do
X-mover:
case RIGHT:
if(col == console.getCols()-2 && row == console.getRows()-1){
console.alarm();
}
else if(col < console.getCols()-1){
col++;
}
break;
case DOWN:
if(row == console.getRows()-2 && col == console.getCols()-1) {
console.alarm();
}
else if(row < console.getRows()-1){
row++;
}
break;
Removing if else statement from console.display() function.. It is done by condition operator
void Console::display(const char* str, int row, int col, int fieldLen){
setPos(row, col);
int i;
int lenght;
lenght = strlen(str);
for(i=0,fieldLen==0?fieldLen=lenght:i=0;i<fieldLen;str[i]!=0?putChar(str[i]):putChar(' '),i++);
}
Saturday, 26 January 2013
Friday, 25 January 2013
Project 0.1
trying hard to finish it as soon as possible...but overall it is very interesting to do.... :)
Monday, 21 January 2013
OOP344 week 2 Exercises
#include<stdlib.h>
using namespace std;
int main(int argc, char* argv[])
{
int sum;
if(argc == 3)
{
cout << "Sum of the number is: "<< atoi(argv[1]) * atoi(argv[2]) << endl;
}
else
{
cout << "Please enter thr correct input" << endl;
}
return 0;
}
#include<stdlib.h>
using namespace std;
int main(int argc, char* argv[])
{
int sum;
if(argc == 3)
{
cout << "Sum of the number is: "<< atoi(argv[1]) / atoi(argv[2]) << endl;
}
else
{
cout << "Please enter thr correct input" << endl;
}
return 0;
}
Wednesday, 9 January 2013
First day in OOP344 class....
I want to share my experience of programming in Seneca College. Please give me comments and any relevant information related to OOP344.
Thanks
Pankaj Sama