Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Data structures

Data structures

caffeineaddict
Journal of caffeineaddict · · 1 min read
667 3
I'm taking a data structures class this semester and I quite like it. The programs, for me at least, have been really easy (queues, and a hash table implementation), others in the class seem to be struggling somewhat. This isn't to brag, but a lot of them seem to think that they can code up anything an hour before it's due and of course, most of them don't make it.

Ah well, I started on the next project today, which I should have done rather soon since I can reuse a lot of the code from the previous project, just implementing a different data structure. Today I coded up a small parser that I was happy with to sort of tokenize a string into its various parts.

Given a string with the following format:

data1;data2;etc.

the function returns each part. It seems to me that there would be ways already implemented to do this sort of thing with strings, but I haven't found it. It was a nice exercise at least. I'm sure it's not the most efficient, but it's easy to use and gets the job done. If you can use it, by all means, have at it.

string getToken(string& initial, char delim){	string temp = "";	int length = (int)initial.size();	for(int i=0; i	{		temp += initial.at(i);		if(initial.at(i) == delim)		{			initial.erase(0, i+1);			temp.erase(i, 1);			return temp;		}	}	return temp;}

Discussion

Loading comments...