its a very easy program, simply sort the vector and then do a linear count.


sort(myvector.begin(), myvector.end());

iter1 = myvector.begin();

while(iter1 is not up to the end)
while(iter1 is not last eliment AND iter1 and iter1+1 same element)
//calculate your count. simple count++ wont work ;) you have to think of this two situate, 112 and 11112 .. notice in first sequence one two 1 and in second sequence 4 1.


Think about it and let me know if you have problem of understanding it.

You dont have to delete or erase, run it in a while loop, every time you find a occurence, start searching after the found position of the sequence

here is a sample, modify it for your need:

int main () {
vector<int> myvector;
vector<int>::iterator it;

// set some values: myvector: 10 20 30 40 50 60 70 80 90
for (int i=1; i<10; i++) myvector.push_back(i*10);

for (int i=1; i<10; i++) myvector.push_back(i*10); myvector: 10 20 30 40 50 60 70 80 90 10 20 30 40 50 60 70 80 90

// using default comparison:
int match1[] = {40,50,60,70};
it = search (myvector.begin(), myvector.end(), match1, match1+4);

if (it!=myvector.end())
cout << "match1 found at position " << int(it-myvector.begin()) << endl;
cout << "match1 not found" << endl;


it = search (it+4, myvector.end(), match1, match1+4);

if (it!=myvector.end())
cout << "match1 found at position " << int(it-myvector.begin()) << endl;
cout << "match1 not found" << endl;

return 0;


Do this and see what happened:

template <typename T> class Queue : public CharQueue <T>

use the accept() function to accept the new socket, and for every socket start a thread, which will listen and send.

You can use poll() or select() to listen on multiple sockets, so you can even use one thread for all the sockets.

read about accept, poll and select, also thread.

Practice as much as possible.

And think simple.

You just have to give output "" and " " in front of "" for row 2, 5 and 7

for(i = 1; i <= 8; i++){

    //For row 2 or 5 or 7, we will give output  a space
     if( i == 2 || i == 5 || i == 7)
            cout << " "
      for(j = 1; j <= 7; j++)
            cout << "*"

     cout << endl;


Why you are doing it as BFS,

so far i understand you just have to give output for the adjacent nodes, and that are already mention in the input,

0 1 1 0
1 0 0 0
1 0 0 1
0 0 1 0

there is already a path between (0,1), (0,2), (2,3)

you dont need BFS to give this ouput, just check the matrix, if there is a path between them give output.

for(i = 0; i < NumberOfNodes; I++)
for(j = 0; j < i; j++)
if(there is a path between i and j)
give output


First thing is error:
StateSpace *state = fringe.front(); // Returns top of fringe
fringe.pop(); // and now you are deleting it!!! pop also calls the destructor. so if you are accessing state after this, thats invalid memory access..

if( a >= 0 && a < 3 && b >= 0 && b < 3 ) // you are not checking if this state is arelady visisted

Now i would like to comment about the coding, here coding style is more like c, then c++

I would suggest to implement a local class or structure to keep the state in the class it self.


class BFS{
struct state{
//state holder





anyway concentrate on the problem first, then you can go for crazy oop :D

first thing i notice is tree data structure is not correct
and recursion here wont work as there is some fundamental mistakes.

data structure should be something like following

struct node
char title[TITLE];
struct node parent;
struct node
firstchild; //This is the head of the LL that is the neighbors
struct node childrenlist; // this is the list of all children, starting from 1st child
struct node

now here is the sudo code of recursion:


struct node searchtree(struct node parent, char *title1)
if(parent is NULL)
return NULL;
if(parent title match title1) //wohoo we found it
return parent;

 for(every children of this parent) // this is the tricky loop for the parent, try it first..
      if( searchtree(child, title1 ) )
           return child; // this will be parent of your new child which you want to insert;



call it from main

parent = searchtree(root, title1);
if(parent is null)
//oppps we didnt find parent
//insert the child, again this is little bit tricky, as you have to insert it as firstchild is it is the firstchild, or in the children list of this parent

i hope this was helpful

miss typed:

will be
if( WIFEXISTED(stat_val) )


I think its not because of the different compiler, its because may be synchronization of parent and child is not happening properly, wait is getting executed even before child process starting.. or something like that?


try this code and see what happened:


pid = fork();

case -1:
perror("Fork failed");
case 0:
//this is child;

if(pid != 0)
int stat_val;
pid_t child_pid;

child_pid = wait(&stat_val);

printf("Child has terminated with exit code %d\n", WIFEXISTED(stat_val));
printf("Child has existed abnormally\n");

// Do some child code here..


Linux or windows?

If it is windows then i cant help :)

In Linux any plugin usually developed as a SO file (shared library) which can be loaded runtime by a server which knows which interface to load, (usually a structure with function pointers)

A tutorial on [URL="

I develop code on Mac and Linux for unix platform, and mainly server side code, so i have very little(actually none) experience with GUI development, anyway, I use Eclipse on centos and mac. Never tried any IDE or any development on windows ;)

I also like netbean.

IMHO use netbean for java, eclipse for c++ and java. :)

pjsip is a very good sip stack.


Have a look at [url][/url] source code, it uses libpcap library.

Best way to learn anything to work with opensource.

You can use libpcap library, or if you want to develop everything, then have a look at that library how they have implemented.

dont just copy and paste the code, first try to understand the code, then it will be much more helpful to develop it.

I just want share my 2 cents,

you can implement typelist and variant, here is a library which has demonstrate and explained implementation of these design patterns, this is really powerfull.


Thanks mike,

I had similar solution but your one is much more generic and well written.

I am just learning templates advance use. I am just picking up several well known problems/design patterns, and trying to write my own template class to implement those.

I have installed boost and planning to do some code study of boost.

Do you contribute in the boost library?



Thanks both of you for answers.

apologies as my english is not so good, so may be i wasn't clear about the question.

@firstPerson, its not designing question, and I can show lot of examples where you need this kind of generic library class, for instance..

We want to implement a SmartPointer generic class for our use, now we can implement smart pointer in so many different ways. @Mike, now here we can provide the policy classes for different different ways/mechanisms/policy.

In our SmartPointer class we want to provide a way so that user of this class can do certain check before this object get deallocated.

Now lets say there are completely two different kind of object.
one is class MySpecialSocket, this wants to check if the socket has been closed and there are more data to read/write before get deallocating.

another class PausedGame, wants to provide another method to check if the game is still paused, but pointer is getting deleted!!!!

user of SmartPointer may not want to do the check also as his object might not need any check.

template <T>
class SmartPointer
//Smart pointer implementation


            if(condition doesn't match)
                    throw "Not Good, we know we shouldn't throw exception from here but still people should know";




below is the code of those two class:

class MySpecialSocket{

//this is the check method we have to provide to SmartPointer
bool isSocketStillOpen{

code for paused game


class PausedGame{

//this ...

This is just for fun and to see how people do it, it will help me to learn different techniques also.

If no one answers i will understand. :)

Lets say you have a template class. You want a certain method of this class will have some sort of checking mechanism before doing a operation.

Different types of object need different kinds of checking. User of this class know whether he needs to do the check or not. If he needs to do the check then he has to provide a function to this template which template class will call to do the check.

How do you make it generic? for better understanding, below code is to demonstrate what our goal is"


// This is only an example, you can change anything to make it work

template <class T>
class JustForFun{

     if( /*CHECK THAT Function*/ ){
            cout << "condition doesnt match" << endl;

      //some operation


What are you trying to do? can you please try to explain the logic behind this while loop?
I think you want to print out a calendar, but the logic below wont work at all.

while (count<=days){
case 1:


case 2:

    cout<<"\t"<<count<<" "; break;

case 3:

    cout<<"\t\t"<<count<<" "; break;}// by the way case 3 does not display correctly at all...

count++; //WHY COUNT IS HERE??????


First try to give only following output using a loop.

1 2 3 4 5
6 7 8 9 19
11 12 13 14 15

after that..

which day of the week is starting day of the month?

ok, you dont have to worry this right now, first try to give a proper output of the calendar assuming that Monday is the 1st day of the month.

After that we can concentrate on this question.

Passing by reference/pointer should work, are you sure your are passing by reference, not creating a local copy?

if you post some code, then it will be much more helpful to figure out why recursion is not working with reference.


you are adding local vairble to the list, so when you are accessing it, that memory is already freed as it was local vairble.

void City::setNextCity(City city) {

//city is local vaible here!!

City* test = nextCities->GetLastElement();};


I havent post the fix, i guess you will be able to figure out how to fix it.

Oppss miss typed, any true wont generate error

//No compile time error
STATIC_CHECK(2 >= 1, two_is_not_smaller_than_one);

//No Compile time error
STATIC_CHECK(true, two_is_not_smaller_than_one);


I was waiting for someone to post a better and more specific solution to you.
I dont consider myself as c++ guru. So definitely there will be better solution, but here is one of the technique i learned from Modern C++ deisgn of Andrei Alexderscu.

you can catch compile time error like below

template <bool>
struct CompileTimeChecker

template <>
struct CompileTimeChecker <false> { };

define STATIC_CHECK(expr, msg)\

class ERROR##msg{};\
CompileTimeChecker<expr> tempvar(new ERROR

int main(int argc, char *args[]){

    // This will give compile time error, use it like traditional assert()

    //this will generate compile time error


Following is the error i get on my mac book for the following check.
compiletime.cpp:34: error: no matching function for call to ‘CompileTimeChecker<false>::CompileTimeChecker(main(int, char*)::ERROR_two_is_not_smaller_than_one)’

   STATIC_CHECK(2< 1, two_is_not_smaller_than_one);
    return 1;



I believe i dont have to explain this code to you.

Happy coding.


OK, So far looks good, but do you want more generic?

IF NO, then dont have to read any more.
But YES ? Then you can add policy design pattern with it using template.

there are several kind of BST (RED-BLACK, AA, AVL, SPLAY.. it goes on and on)
All are self balancing binary search tree, travesing is same, but adding/deleting is different.

So you can add policy in this class now for adding/deleting policy.


template <
class KeyType,
class ValueType,
template <class> class BSTPolicy=RedBlackTree

class BST : public BSTPolicy <KeyType,ValueType>
----- Here Goes BST CODE --

BSTPolicy is defiened as, BSTPolicy will implement two method, one is add, another is remove.

This is one of the most powerfull feature of templalte..


Happy coding.

Use matrix, for any graph matrix is the best structure to use, you can easily find the edges in O(1).

For BFS, you need to implement a queue to do the BFS on the graph matrix.

You have bytesPerRecord=38
but accounts.txt has different size of records which ultimately messing up your seekg calculation. Make sure all the records in account.txt is of size 38 bytes.

You have bytesPerRecord=38
but accounts.txt has different size of records which ultimately messing up your seekg calculation. Make sure all the records in account.txt is of size 38 bytes.


Please search at search at google at there are lots of information regarding this.

But for very simple info, every process created by the operating system has 3 memory blocks to store variables,fucntions.

These are:
Heap: Dynamically allocated memory are created here. if you allocate any memory using alloc/calloc/malloc, new, operator new, these will go here.
Static memory: where global and static variables are stored.
Stack: Stack is where auto vairables are stored, automatic variables are the variables which you have declared in the function. like, int a; float b; int a[100]

I hope this helps.

char s1[100] = "Lets see what it does?", s2[100]=" ", *tok;

    tok = strtok(s1, s2);

    while(tok != NULL)
            printf("%s\n", tok);
            /*Put tok in your struct here*/
            tok = strtok(NULL, s2);