C++ School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C++ Expert!

Join 307,124 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,012 people online right now. Registration is fast and FREE... Join Now!




Data Structures In C++ Tutorial

3 Pages V < 1 2 3  
Reply to this topicStart new topic

> Data Structures In C++ Tutorial, Writing Data Structures using OOP in C++

Rating  4
KYA
Group Icon



post 1 Dec, 2008 - 01:42 PM
Post #41
darkrut, post in the C++ forums, you'll get a better response there.
Go to the top of the page
+Quote Post

darkrut
*



post 2 Dec, 2008 - 12:21 AM
Post #42
QUOTE(KYA @ 1 Dec, 2008 - 01:42 PM) *

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
CODE

#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;}

    
                            

void 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();
            }    



}
Go to the top of the page
+Quote Post

kkb
*



post 22 Jan, 2009 - 01:45 AM
Post #43
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?
Go to the top of the page
+Quote Post

mrkulit
*



post 2 Mar, 2009 - 05:34 AM
Post #44
could you edit the BST to turbo c pls.. i cant understand C++,.. T_T
Go to the top of the page
+Quote Post

polymath
Group Icon



post 22 Mar, 2009 - 11:21 AM
Post #45
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!
Go to the top of the page
+Quote Post

cmaster
**



post 3 May, 2009 - 03:37 AM
Post #46
Cool tutorial. Also one can explore data structure tutorials to get more info about subject.
Go to the top of the page
+Quote Post

itengineer
*



post 11 May, 2009 - 07:23 AM
Post #47
hi everyone out there.........
i am new to pointers and dont know exactly how to removw and avoid MEMORY LEAKS in a program........
please let me know if anybody has a link to any such tutorial.......
Go to the top of the page
+Quote Post

bob3333
*



post 31 May, 2009 - 10:00 AM
Post #48
It's
CODE
iter++
not
CODE
i++
Go to the top of the page
+Quote Post

yudhistre
*



post 3 Aug, 2009 - 06:31 AM
Post #49
Thanks for the time taken to do this, Highly Appreciated

Keep up the good work

Go to the top of the page
+Quote Post

TonyTheBest
*



post 24 Sep, 2009 - 12:36 PM
Post #50
Im Sorry... Im newb to coding... don't know what ur doing sad.gif Im SOrry
Go to the top of the page
+Quote Post

ceaser
*



post 25 Sep, 2009 - 05:57 AM
Post #51

CODE
else
     {
                for(int j=0;j<=al;j++)
                {
                        if((j+1)<=al)
                        {
                                tmp=t[j+1];
                                t[j]=tmp;
                        }
                        else
                        {
                                al--;

                        if(al==-1)
                                dl=-1;
                        else
                                dl=0;
                        }
                }
     }
  }

i didnt understand this piece of code j+1<=al what does this represent ....
can u plz explain the whole thing?
Go to the top of the page
+Quote Post

wowelf
*



post 25 Oct, 2009 - 03:19 AM
Post #52
smile.gif cooler than cool
Go to the top of the page
+Quote Post

wowelf
*



post 29 Oct, 2009 - 03:27 AM
Post #53
hard to change my mind from FIFO TO FILO. icon_up.gif smile.gif biggrin.gif
Go to the top of the page
+Quote Post

wowelf
*



post 29 Oct, 2009 - 03:39 AM
Post #54
QUOTE(ByteWyse @ 6 Jan, 2007 - 10:38 AM) *

QUOTE(born2c0de @ 6 Jan, 2007 - 05:32 AM) *

I had no idea that endl also flushes buffers.
Are you sure?
Thanks for the info smile.gif


Yep.
See: http://www.cplusplus.com/reference/iostrea...ators/endl.html

Thx .
Go to the top of the page
+Quote Post


3 Pages V < 1 2 3
Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 02:07PM

Live C++ Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month