Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Linked lists and insertion sort

Reply
Thread Tools

Linked lists and insertion sort

 
 
Jochus
Guest
Posts: n/a
 
      04-19-2005
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/in...oj/CGI/cgi.cpp
-> header:
http://members.lycos.co.uk/jochus/in...Proj/CGI/cgi.h


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      04-19-2005
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.

 
Reply With Quote
 
 
 
 
Jochus
Guest
Posts: n/a
 
      04-20-2005
"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 ...


 
Reply With Quote
 
Jochus
Guest
Posts: n/a
 
      04-21-2005
Problem solved: we were deleting too much ...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Airplane Program with Linked Lists. The linked list portion is veryconfusing to me. jawdoc C++ 9 03-10-2008 03:38 AM
Insertion Sort on a linked list Java Newbie Java 2 02-09-2007 07:53 PM
using insertion sort with a linked list Julia C++ 6 08-11-2006 08:11 PM
Generating a char* from a linked list of linked lists Chris Ritchey C++ 7 07-10-2003 10:12 PM
Generating a char* from a linked list of linked lists Chris Ritchey C Programming 7 07-10-2003 10:12 PM



Advertisments