TEMPLATED DOUBLE LINKED LIST TESTER

Posted: March 21, 2012 in Uncategorized
#include <iostream>
using namespace std;

#include "tqueue.h"

template <class T>
void print(Tqueue<T>& Q){
  bool done = false;
  Q.goHead();
  cout<<"NULL <- [HEAD] ";
  if(!Q.isEmpty()){
    do{
      cout<<Q.visit();
      if(Q.goNext()) cout<<" <=> ";
      else{
        done = true;
      }
    }while(!done);
  }
  cout<<" [TAIL] -> NULL"<<endl;
  cout<<endl<<endl;
}

int main(){
  Tqueue<int> Q;
  cout<<"Before Data to be Added:"<<endl;
  print(Q);

  for(int i=1;i<=6;i+=1){
    Q.append((rand()%rand())%100+1);
  }
  cout<<"After Data Added Ramndomly:"<<endl;
  print(Q);

  cout<<"After Assending Order:"<<endl;
  Q.sort();
  print(Q);
  cout<<"After Dessending Order:"<<endl;
  Q.sort(0);
  print(Q);

  cout<<"Let's POP some data:"<<endl;
  cout<<Q.pop()<<endl;
  cout<<Q.pop()<<endl;
  cout<<Q.pop()<<endl<<endl;
  cout<<"After Poped some data:"<<endl;
  print(Q);

  cout<<"After Pushed some data:"<<endl;
  Q.push(111);
  Q.push(555);
  Q.push(999);
  print(Q);

  Q.append(55);
  cout<<"AFTER APPENDED A DATA:"<<endl;
  print(Q);


  cout<<"MOVE CURRENT TO SECOND NODE (if exist) AND USE INSERTBEFORE TO ADD 1234:"<<endl;
  Q.goHead();
  Q.goNext();
  Q.insertBefore(1234);
  print(Q);

  cout<<"MOVE CURRENT TO FIFTH NODE (if exist) AND USE INSERTAFTER TO ADD 1000:"<<endl;
  Q.goHead();
  Q.goNext();
  Q.goNext();
  Q.goNext();
  Q.goNext();
  Q.insertAfter(1000);
  print(Q);

  cout<<"MOVE CURRENT TO SECOND NODE (if exist) AND REMOVE:"<<endl;
  Q.goHead();
  Q.goNext();
  Q.removeCurrent();
  print(Q);

  getchar();
  return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s