Hey guys. I'm trying to create a program which adds, searches & removes items from an array & i've been messing around with the code, trying to find answers on the internet but so far no dice. Could any of you help out?

void removeString(List& s, string strKey, const int iARRAYSIZE, int result)
{
	cout << "Enter the string to be deleted" << endl << ":" ;
	cin >> strKey;
	cout << endl ;
	for (result = 0; result < iARRAYSIZE; result++ )
	{
		if ( s.strList[result] == strKey )
		{
			for (int i = s.iListIndex; i < s.iListLength ; i++)
			{
				s.strList[s.iListIndex] = s.strList[s.iListIndex+1];
				s.strList[s.iListLength-1] = 0; //more than one operator 
			}                                       //matches these operands
			cout << "Succesfully Deleted" << endl;
		}
		else
		{
			cout << "Error 404" << endl;
		}
	}
}

This is what i have so far. I know it's crap but that's why i need help! Thanks :D

Recommended Answers

All 4 Replies

Just some few comments/questions first.

1) you might want to think twice on that hungarian notation.
2) Does the order of the elements in the string matter? For example does the last element has to be the last ? So does the element position matters relative to its neighbors?

1) The names are temporary, ill work on those later. What's wrong with them anyway? :S
2) not really, they are bubble sorted soon after they're added. Yes the array size is a constant so the user cannot add any more strings after the array is full and needs to delete to add anymore(obv) ..

Any hints?

If the order doesn't matter then what you can do is
1) find the element A
2) If A does not exist then exit
3) Else if A does exist, then swap A with the last element in the array
4) Then simply set the last element to 0, and decrease the list's size

Then your done.

For me that notation is just a little annoying and sometimes can be in the way rather than helping me.

that did not really help me but what ever .. i figured it out .. i came up with this code to anyone reading who wants this

int linearSearch(List& aList,const string& strKey) 
{
	int result;
	if(aList.iListIndex <= 0)
		result = iERROREMPTY;
	else
	{
		int i;
		for (i = 0; i < aList.iListIndex && aList.strList[i] == strKey; i++){;}
		if(i == aList.iListIndex)
			result = iERRORNOTFOUND;
		else
			result = i;

	}
	return result;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.