• (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5

Data Structures In C++ Tutorial Writing Data Structures using OOP in C++ Rate Topic: ****- 20 Votes

#31 blacksnake  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 23-July 07

Posted 07 October 2008 - 03:37 AM

can you show the basics of expression trees?
Was This Post Helpful? 0
  • +
  • -

#32 casterden  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-October 08

Posted 22 October 2008 - 10:05 AM

/*BINARY SEARCH PROGRAM BY SUMAIR IRSHAD*/
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int arr[]={1,3,5,7,9,11,13,15,17,19};
int i,target,start=0,end=10,mid;
printf("enter target");
scanf("%d",&target);
while(target!=arr[mid])
{
mid=(start+end)/2;
if(target==arr[mid])
{
break;
}
else if(target<arr[mid])
{
end=mid-1;
}

else if(target>arr[mid])
{
start=mid+1;
}
}
printf("target found at %dth location",mid+1);
getch();
}

Was This Post Helpful? 0
  • +
  • -

#33 bonnie1702  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-October 08

Posted 30 October 2008 - 02:23 AM

Hey there!

I'm new to c++ and new to this forum. I find the data structure tutorial very easy to read and understand. I haven't yet tried all the code yet. but I did do the one for stack (push and pop) and when I compiled, I got the error:

37 C:\c++Stuff\Stack.cpp [Warning] converting to non-pointer type `int' from NULL

I am using bloodshed's dev c++, so I thought I'd let you know that is whats happening. So if there is an error somewhere it would be nice to fix it. Does anyone else have any similar compilation errors with any of the code listed in the tutorial?

cheers
nm :)
Was This Post Helpful? 0
  • +
  • -

#34 bonnie1702  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-October 08

Posted 31 October 2008 - 01:59 AM

Hi, back again!

I fixed up the minor error in the stack class by replacing the NULL with 0. Now it compiles and runs fine.

I have since tried the queue class and there are a couple of minor typos ie., ensure that tmp is actually spelt temp, and in the second for loop in the main method, you need to declare iter as int iter; if you dont want keep typing the data type for every for loop, just declare it as a global in the main, like such: int iter.

After fixing up those, I ran the program and did not get the same output as in the example. this is what i got instead:

Quote

Queue before adding elements:
2000215017 0

Addition number: 1 : 2000215017 0 32
Addition number: 2 : 2000215017 0 32 23
Addition number: 3 : 2000215017 0 32 23 45
Queue is Full
Addition number: 4 : 2000215017 0 32 23 45
Queue is Full
Addition number: 5 : 2000215017 0 32 23 45

Queue after adding elements 2000215017 0 32 23 45

Deletion number: 1 : 0 32 23 45
Deletion number: 2 : 32 23 45
Deletion number: 3 : 23 45
Deletion number: 4 : 45
Deletion number: 5 : Empty


so there you have it.

has anyone else had any problem with the example code?

cheers all
nm B)
Was This Post Helpful? 0
  • +
  • -

#35 ali khan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-November 08

Posted 12 November 2008 - 11:07 PM

View Postborn2c0de, on 17 Sep, 2006 - 01:12 AM, said:

I'm glad to know it helped you.

i have a pproblem in the topic escape sequences is there any 1 to help me?????????????????????
Was This Post Helpful? 0
  • +
  • -

#36 bonnie1702  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-October 08

Posted 27 November 2008 - 01:28 AM

Would be good if you could add to your tutorial some stuff on double linked lists

regards
NM :P
Was This Post Helpful? 0
  • +
  • -

#37 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Posted 28 November 2008 - 07:22 PM

bonnie, I'll look into seeing if that would be worth its own tutorial.
Was This Post Helpful? 0
  • +
  • -

#38 darkrut  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-December 08

Posted 01 December 2008 - 02:42 AM

i have a problem! if the condition is true at the first while it works...but at the second "while" it doesn't delete the node that the condition is true for!thank you for helping me
//....
struct node  
 {  
   string kelima;  
   int compteur;
   node *link;  
 };// .........
void delnode(int n)
			{	  node*temp;
				   node*teo; 
				 
				   
				   
						 while(top->compteur<n)
						 {   
								top=top->link;if(top==NULL)break;
						 }temp=top;
						 
						  while(temp!=NULL)
						  { if(temp->compteur!=n)
								{ 
								teo=NULL;
								 teo=temp->link;
								
								 temp=teo;
								}
						 	 
									 
							else temp=temp->link;
						}		 
						
							  
							
			 }

Was This Post Helpful? 0
  • +
  • -

#39 violaris  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 14
  • Joined: 30-November 08

Posted 01 December 2008 - 04:04 AM

This is so great, I have passed my Data Structures midterm by only following this tutorial and practicing with it!
Was This Post Helpful? 0
  • +
  • -

#40 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Posted 01 December 2008 - 02:42 PM

darkrut, post in the C++ forums, you'll get a better response there.
Was This Post Helpful? 0
  • +
  • -

#41 darkrut  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 01-December 08

Posted 02 December 2008 - 01:21 AM

View PostKYA, on 1 Dec, 2008 - 01:42 PM, said:

darkrut, post in the C++ forums, you'll get a better response there.

like you asked for ,KYA , here my code!!thank you for helping
#include<iostream>
#include<fstream>
#include<string>

#include <vector>

using namespace std;
struct node  
 {  
   string kelima;  
   int compteur;
   node *link;  
 };  
   
 class Pile  
 {  
	   private:  
			   node* top; 
			   
   
	   public:  
			  Pile()  
			  {  
				 top=NULL;
				 
			  }  
				
			  void EMPILER(int n,string terme)  
			  {  
				 node *tmp;  
				 tmp=new node;  
						cout<<terme<<endl;		   
				 tmp->kelima=terme;	
				 tmp->compteur=n;
				 
				 
				 
				 tmp->link=top;  
				top=tmp; 
			  }  
   
			  void VerifInc(string terme)  
			 {  int trouve=0,z;
				 node *tmp;  
				 tmp=top;
			 while(tmp!=NULL)
			 {   
				if (terme.compare(tmp->kelima)==0) 
				{tmp->compteur++;
				z=tmp->compteur;trouve=1;break;}
				 tmp=tmp->link;  
				 
			 }
				 if(trouve==0)  
				 {  
					EMPILER(1,terme);  
					   
				}  
				
				 
				  
			  }  

			int CompTerme(string terme)
			{ int trouve=0,v;
				 node *tmp;  
				 tmp=top;
				 while(tmp!=NULL)
			 {   
				if (terme.compare(tmp->kelima)==0) 
				{v=tmp->compteur;return v;}
				  tmp=tmp->link;  
			}	 
			 
 ///////////////////////////////////////////////////////////////Here is my probleme/////////				  
					return 0;  
			}		   
			void RESTerme(int n)
			{	  node*temp;
				   node*teo;
				
				  
				  
						 while(top->compteur<n)
						 {  
							 temp=top->link;delete top;top=temp;if(top==NULL)break;
						 }temp=top;					
						  while(temp!=NULL)
						  {  if(temp->compteur<n)
						 
						  {teo=temp->link;
						  temp->link=teo->link;}
							else	temp=temp->link;
						}		
						
							  
							
			 }
	}; 				 
/////////////////////////////////////////////////////////////////////////////////////////////
		

 
string RLTrim(string term)
{ string sof=" ";
if (term!=" "){

int x=term.length();
if
 
	(term.compare(0,1,sof)==0)
{term=term.erase(0,1);
   if(term.compare(term.size(),1,sof))
   term.erase(term.size(),1);
}
}
   return term;
}
string decomposer(string term)
{int foundv,foundpv,founddp;
foundv=term.find(",");
foundpv=term.find(";");
founddp=term.find(":");
		while(foundv!=string::npos)
			
		{	term.replace(foundv,1," ");
			foundv=term.find(",");
		}	
		
		while(foundpv!=string::npos)
		{
		term.replace(foundpv,1," ");	
		foundpv=term.find(";");
		}
		while(founddp!=string::npos)
		{
			term.replace(founddp,1," ");
			founddp=term.find(":");
		}
		
	return term;
}



void enregistrerPh (string phrase)
{   ofstream myfile;
	myfile.open("phrase.txt",ios::app);
	if (myfile.is_open())
	{
	 myfile << phrase + "\n";
	}
	myfile.close();
	
}
void enregistrerTerm (string jomla)
{   ofstream myfile;
	myfile.open("terme.txt",ios::app);
	if (myfile.is_open())
	{
	 myfile << jomla + "\n";
	 
	}
	myfile.close();
	
}
void FreeStopList(string phrase,string terms[])
{
int i=0,xposition=0,trouve=0,foundE;
string MajTerm;
string term;
phrase=RLTrim(phrase);
phrase=decomposer(phrase);
foundE=phrase.find(" ");

while (phrase!=""){
	term=RLTrim(phrase);
term=phrase.substr(0,foundE);
	
	phrase=phrase.erase(0,foundE);
	
	phrase=RLTrim(phrase);
	foundE=phrase.find(" ");
	for(i=0;i<750;i++)
	
	






	{	if (term.compare(terms[i])==0)
									{trouve=1;}
								
								}	if (trouve==0)
									enregistrerTerm(term);
								trouve=0;
	if (phrase.compare(term)==0)
break;

}
	

}


string TraitementPh(string line)
{int foundPI,foundPE;


foundPE=line.find("!");
foundPI=line.find("?");

while(foundPE!=string::npos)
			
		{	line.replace(foundPE,1,".");
			foundPI=line.find(",");
		}
 while(foundPI!=string::npos)
			
		{	line.replace(foundPI,1,".");
			foundPI=line.find(",");

		}
 return line;
}


string decomposerln(string line,string stoplist[])
	{
	
	int foundPoint;
	 string ph;
 foundPoint=line.find(".");
  
 while(foundPoint!=string::npos)

 {   ph=line.substr(0,foundPoint);
	ph=RLTrim(ph);
		enregistrerPh(ph);
		FreeStopList(ph,stoplist);
	 cout << ph+"\n";
			
	line.erase(0,foundPoint+1);
	foundPoint=line.find(".");
 }
return line;}

	
							

int main()



{
	string term;
int i=0,z=0;
string v,kelima,mot,fichier="test.txt";
string stoplist[2000];

string line;
ifstream myfile("StopList.txt");
if (myfile.is_open())
{
 while (!myfile.eof())
 {getline(myfile,line);
 z++;
 stoplist[i]=line.erase(line.length());
 mot=stoplist[i];
 if (mot.length()>3)
 {kelima=RLTrim(mot);
 stoplist[i]=kelima;}
 i++;
 }myfile.close();




}
else cout << "unable tu open StopList";


string jomla=" ";
ifstream monfile("document.txt");
if (monfile.is_open())
	{
			 while (!monfile.eof())
				 {getline(monfile,line);
if (line.compare("")!=0)
{	jomla+=" "+line;

					jomla=TraitementPh(jomla);

					jomla=decomposerln(jomla,stoplist);

	}
			 }

}else cout << "unable tu open Document";


	
	Pile s;

	string lines;int sof;
	
			ifstream myfiles ("terme.txt");
			if (myfiles.is_open())
			{
				while (! myfiles.eof() )
					{getline(myfiles,lines);
						s.VerifInc(lines);
					}	
				
					s.RESTerme(2);	//here the problem
//sof it's a test...
					sof=s.CompTerme("david");
					cout << sof<<"occurence du mot david"<<endl;
					sof=s.CompTerme("caca");
					cout << sof<<"occurence du mot caca"<<endl;
					sof=s.CompTerme("People");
					cout << sof<<"occurence du mot people"<<endl;
					sof=s.CompTerme("sara");
					cout << sof<<"occurence du mot sara"<<endl;
					sof=s.CompTerme("zozo");
					cout << sof<<"occurence du mot zozo"<<endl;
					sof=s.CompTerme("sofian");
					cout << sof<<"occurence du mot sofian"<<endl;
					sof=s.CompTerme("boob");
					cout << sof<<"occurence du mot boob"<<endl;
				
				myfiles.close();
			}	



}

Was This Post Helpful? 0
  • +
  • -

#42 kkb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-January 09

Posted 22 January 2009 - 02:45 AM

hi friends i am new in this group so if you have any usefull material about any programing language then i am requesting you to share with me every knowledge you can ?

please send me any emails related to programing concept's then note my email address that is

jae.sindh@gmail.com

i will be very thankfull to all of you dear friends?
Was This Post Helpful? 0
  • +
  • -

#43 mrkulit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-March 09

Posted 02 March 2009 - 06:34 AM

could you edit the BST to turbo c pls.. i cant understand C++,.. T_T
Was This Post Helpful? 0
  • +
  • -

#44 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Posted 22 March 2009 - 12:21 PM

The only thing i think would improve the tutorial: Perhaps add a section on templating one of the simpler structures (i.e. stack)? Templates allow for greater functionality and the STL is also implemented in this way.

Great tutorial!
Was This Post Helpful? 0
  • +
  • -

#45 cmaster  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 53
  • Joined: 18-November 08

Posted 03 May 2009 - 04:37 AM

Cool tutorial. Also one can explore data structure tutorials to get more info about subject.
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5