473,382 Members | 1,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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/in...oj/CGI/cgi.cpp
-> header:
http://members.lycos.co.uk/jochus/in...Proj/CGI/cgi.h
Jul 23 '05 #1
3 2424
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.

Jul 23 '05 #2
"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 ... :-(
Jul 23 '05 #3
Problem solved: we were deleting too much :-) ...
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Kent | last post by:
Hi! I want to store data (of enemys in a game) as a linked list, each node will look something like the following: struct node { double x,y; // x and y position coordinates struct enemy...
1
by: Booser | last post by:
// Merge sort using circular linked list // By Jason Hall <booser108@yahoo.com> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> //#define debug
7
by: Kieran Simkin | last post by:
Hi all, I'm having some trouble with a linked list function and was wondering if anyone could shed any light on it. Basically I have a singly-linked list which stores pid numbers of a process's...
4
by: MJ | last post by:
Hi I have written a prog for reversing a linked list I have used globle pointer Can any one tell me how I can modify this prog so that I dont have to use extra pointer Head1. When I reverse a LL...
3
by: chellappa | last post by:
hi this simple sorting , but it not running...please correect error for sorting using pointer or linked list sorting , i did value sorting in linkedlist please correct error #include<stdio.h>...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
6
by: Julia | last post by:
I am trying to sort a linked list using insertion sort. I have seen a lot of ways to get around this problem but no time-efficient and space-efficient solution. This is what I have so far: ...
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
10
by: AZRebelCowgirl73 | last post by:
This is what I have so far: My program! import java.util.*; import java.lang.*; import java.io.*; import ch06.lists.*; public class UIandDB {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.