Linked lists and insertion sort



 DEVELOP > c-Plus-Plus > Linked lists and insertion sort

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Jochus"
Date: 19 Apr 2005 08:33:49 AM
Object: Linked lists and insertion sort
Hi!
Today we saw the information about lists. We have an assignment about CGI.
That's all going well, but we're stuck at the insertion sorft of linked
lists
--
void voeg_in_lijst(const char* padname, int matches, match *& bestanden) {
match *hulp;
hulp=new match;
strcpy(hulp->url, padname);
hulp->aantal=matches;
if(bestanden==0 || bestanden->aantal<matches){
if (bestanden==0){
bestanden=hulp;
bestanden->vlg=0;
}
else
{
match *temp;
temp=bestanden;
bestanden=hulp;
bestanden->vlg=temp;
}
}
else{
match *schuiver=bestanden->vlg;
while(schuiver!=0 && schuiver->aantal>hulp->aantal){
schuiver=schuiver->vlg;
}
if (schuiver!=0){ // doe insertion
match *extra=schuiver->vlg;
schuiver->vlg=hulp;
hulp->vlg=extra;
}
}
}
--
voeg_in_lijst is dutch for add_in_list. padname is the name of "file" we
need to add in the list, matches is the frequency a word comes forward en
match *bestanden is a list.
So what do we do ...
We check all the lists untill we found an element that is smaller then our
matches.
And then we add in the list.
But that doesn't work ... We have errors. Something about the memory I
assume.
The problem is, we (3 persons) are searching for the fault for 2 days and
can't find the fault. And it must be something stupid!
But I think it's difficult to help, as I can't explain/translate the
assignment ... maybe you can view the whole cpp file:
http://members.lycos.co.uk/jochus/inwe/2ekan/informatica/Prog%20Proj/CGI/cgi.cpp
-> header:
http://members.lycos.co.uk/jochus/inwe/2ekan/informatica/Prog%20Proj/CGI/cgi.h
.

User: "Rolf Magnus"

Title: Re: Linked lists and insertion sort 19 Apr 2005 09:05:26 AM
Jochus wrote:

Hi!

Today we saw the information about lists. We have an assignment about CGI.
That's all going well, but we're stuck at the insertion sorft of linked
lists

--
void voeg_in_lijst(const char* padname, int matches, match *& bestanden) {

match *hulp;
hulp=new match;
strcpy(hulp->url, padname);

hulp->url is an uninitialized pointer at that point. It must point to some
valid memory big enough to hold the string that padname points to, before
you can use it as target for strcpy.

hulp->aantal=matches;

if(bestanden==0 || bestanden->aantal<matches){
if (bestanden==0){
bestanden=hulp;
bestanden->vlg=0;
}
else
{
match *temp;
temp=bestanden;
bestanden=hulp;
bestanden->vlg=temp;

}
}
else{
match *schuiver=bestanden->vlg;
while(schuiver!=0 && schuiver->aantal>hulp->aantal){
schuiver=schuiver->vlg;
}
if (schuiver!=0){ // doe insertion
match *extra=schuiver->vlg;
schuiver->vlg=hulp;
hulp->vlg=extra;
}
}
}

I can't see any other error ATM.
.
User: "Jochus"

Title: Re: Linked lists and insertion sort 20 Apr 2005 02:32:14 AM
"Rolf Magnus" schreef in bericht:
Jochus wrote:


Hi!

Today we saw the information about lists. We have an assignment about
CGI.
That's all going well, but we're stuck at the insertion sorft of linked
lists

--
void voeg_in_lijst(const char* padname, int matches, match *& bestanden)
{

match *hulp;
hulp=new match;
strcpy(hulp->url, padname);


hulp->url is an uninitialized pointer at that point. It must point to some
valid memory big enough to hold the string that padname points to, before
you can use it as target for strcpy.

Thnx! We forgot to create the url (char) with new! :-$ ...
But we're still getting Segmentation Errors ... :-(
.

User: "Jochus"

Title: Re: Linked lists and insertion sort 21 Apr 2005 05:06:39 PM
Problem solved: we were deleting too much :-) ...
.



  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER