Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Deleting in Linked List
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
imbored




PostPosted: Sat Jan 02, 2010 7:47 pm   Post subject: Deleting in Linked List

What is it you are trying to achieve?
Having a procedure delete a value from the linked list... also make it a circular linked list.


What is the problem you are having?
I understand the box things
[....|...] [XXXX] [....|...]
..|_______________^

etc... but i dont understand how to program it.

Describe what you have tried to solve this problem
i tried replacing the value that needs to be deleted with the next value and it keeps going untill the end.. but it didnt end up great either i programmed it wrong or its just wrong... i started from scratch from what i had before.

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
this is what i got.. it saves the inputs into the linked list and outputs it. it is choppy and inefficient... but i dont really know how to make it more efficient. but first thing is first how to make it delete o.o''
Turing:


var PointerType : collection of
    record
        Data : string (40)
        Next : pointer to PointerType
        Prev : pointer to PointerType
    end record
var Backup : collection of
    record
        Data : string (40)
        Next : pointer to Backup
        Prev : pointer to Backup
    end record
%------------------- procedure---------------------------------------

procedure First (var InsertRecord, ListStart, ListEnd : pointer to PointerType, spNames : string)
    new InsertRecord
    ListEnd := InsertRecord
    ^InsertRecord.Next := nil
    ^InsertRecord.Data := spNames
    ListStart := InsertRecord
end First
procedure bFirst (var bIRecord, bListStart, bListEnd : pointer to Backup, spNames : string)
    new bIRecord
    bListEnd := bIRecord
    ^bIRecord.Next := nil
    ^bIRecord.Data := spNames
    bListStart := bIRecord
end bFirst
procedure InName (var InsertRecord, ListStart, ListEnd : pointer to PointerType, spName : string, var ipAm : int)
    new InsertRecord
    ^InsertRecord.Next := ListStart
    ^ListStart.Prev := InsertRecord
    ^InsertRecord.Data := spName
    ListStart := InsertRecord
    ipAm += 1
end InName
procedure bInName (var bIRecord, bListStart, bListEnd : pointer to Backup, spName : string)
    new bIRecord
    ^bIRecord.Next := bListStart
    ^bListStart.Prev := bIRecord
    ^bIRecord.Data := spName
    bListStart := bIRecord
end bInName
procedure Circular (var InsertRecord, ListStart, ListEnd : pointer to PointerType)
    InsertRecord := ListEnd
end Circular
procedure OutName (ListEnd : pointer to PointerType, ipAm : int)
    var i : int := 0
    var TempList := ListEnd
    loop
        i += 1
        put ^TempList.Data
        exit when i = ipAm
        TempList := ^TempList.Prev
    end loop
end OutName
procedure bOutName (bListEnd : pointer to Backup, ipAm : int)
    var i : int := 0
    var TempList := bListEnd
    loop
        i += 1
        put ^TempList.Data
        exit when i = ipAm
        TempList := ^TempList.Prev
    end loop
end bOutName
%----------------------- main----------------------------------------
var InsertRecord, ListStart, ListEnd : pointer to PointerType
var bIRecord, bListStart, bListEnd : pointer to Backup
var sNames : string
var iAm : int := 1
var iAm2 : int := 1
put "Input the name of a contestant"
get sNames : *
First (InsertRecord, ListStart, ListEnd, sNames)
bFirst (bIRecord, bListStart, bListEnd, sNames)
if (sNames = 'Fin') or (sNames = 'fin') then
    %nothing
else
    loop
        put "Input the name of a contestant"
        get sNames : *
        exit when (sNames = 'fin') or (sNames = 'Fin')
        InName (InsertRecord, ListStart, ListEnd, sNames, iAm)
        bInName (bIRecord, bListStart, bListEnd, sNames)
    end loop
end if
Circular (InsertRecord, ListStart, ListEnd)
cls
iAm2 := iAm
put "List: "
OutName (ListEnd, iAm)
put "Which Contestant do you want to elliminate?"
get sNames
%delete
put "Backup : "
bOutName (bListEnd, iAm2)
put "Remaining: "
OutName(ListEnd, iAm)



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sun Jan 03, 2010 2:10 pm   Post subject: RE:Deleting in Linked List

Well first thing's first, have you investigated this problem yourself? Linked lists are very common, and there are plenty of resources on just about anything to do with them.

Here's a quick link from Google which might help on delete: http://www.cs.bu.edu/teaching/cs112/spring-2000/linked-list-delete/

This is a great way to learn/practice recursion, so try to follow that route. Just go slowly, case-by-case, and ensure that each piece of code you write is accurate.
imbored




PostPosted: Sun Jan 03, 2010 3:31 pm   Post subject: RE:Deleting in Linked List

yea i saw that before but i dont know how to program it... i dont get the C++ codes
[Gandalf]




PostPosted: Sun Jan 03, 2010 4:33 pm   Post subject: RE:Deleting in Linked List

Perhaps try the following site instead, particularly the "modifying lists" section. It may even "convert" you to Python, given that Turing is a very ugly language in which to write linked lists. Smile

http://ada.rg16.asn-wien.ac.at/~python/how2think/english/chap17.htm

Try to generalize what they do for the 2nd element of a linked list to an arbitrary element. I'm sure you can find something to clarify the concept. If you have any specific questions, you can then post them here.
imbored




PostPosted: Sun Jan 03, 2010 4:49 pm   Post subject: RE:Deleting in Linked List

this site is better but reguarding the converting... i can't do that. This is part of an assignment. i was suppose to use pascal but it wasn't working on my computer so i used turing which is already on my computer. Though this site looks alot more helpful i really dont fully understand it. I dont understand how to shift the pointer because i dont fully understand the functions regarding the pointer.

edit : okay nvm.. i read it a few times... and i dont get it lol.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: