VB icon

A small queue class

Email
Submitted on: 8/19/2016 10:18:25 PM
By: Ben128  
Level: Beginner
User Rating: Unrated
Compatibility: C++ (general), Microsoft Visual C++, UNIX C++
Views: 1687
 
     Here is a small queue I made into a class you can add items, set data delete an item hope you find the code usfull.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A small queue class
// Description:Here is a small queue I made into a class you can add items, set data delete an item hope you find the code usfull.
// By: Ben128
//**************************************

//Home made Queue class supports ints only by DreamVB
#include <stdio.h>
class TQue{
private:
	int mIndex;
	int *List;
public:
	void Init(int size);
	void AddItem(int item);
	void SetItem(int index,int item);
	void Clear(){delete[]List;}
	void Delete(int index);
	int FetchItem(int index);
	int FindItem(int item);
	int Count(){return mIndex;}
};
void TQue::Init(int size){
	List = new int[size];
	mIndex=0;
}
void TQue::AddItem(int item){
	List[mIndex] = item;
	mIndex++;
}
int TQue::FetchItem(int index){
	if((index < 0) || (index > mIndex-1)){
		return 0;
	}
	return List[index];
}
void TQue::SetItem(int index,int item){
	if((index <0) || (index >mIndex)){
		return;
	}
	List[index] = item;
}
void TQue::Delete(int index){
	int *temp;
	int i = 0;
	int j = 0;
	temp = new int[mIndex];
	while(i < mIndex){
		if(index != i){
			temp[j] = List[i];
			j++;
		}
		i++;
	}
	if(mIndex > 0){mIndex--;}
	//Set new list data
	List=temp;
}
int TQue::FindItem(int item){
	int idx = -1;
	int i = 0;
	while(i<mIndex){
		if(List[i] == item){
			idx = i;
			break;
		}
		i++;
	}
	return idx;
}


Other 50 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.