| Circular linked list help 
 
	 
	
		| Author | Message |   
		| imbored 
 
 
 
 
 | 
			
				|  Posted: Fri Jan 01, 2010 5:10 pm    Post subject: Circular linked list help |  |   
				| 
 |  
				| What is it you are trying to achieve? make a circular linked list. and make the delete procedure stop when there is only one item left in the list. I am suppose to make it a circular linked list that holds the user input and then afterwards delete some until one is left. Also a backup of the list is needed of the original inputs. and when the program is finish running, it would display the original inputs and the one last remaining input.
 
 but mainly i am trying to get it as a circular linked list.
 ps: if it is circular does that means it loops over and over again from the top to the bottom and back to top. how do i stop it from going to infinite loop when i am deleting and displaying.
 What is the problem you are having?
 i dont understand how to link the ending of the linked list back at top.
 
 Describe what you have tried to solve this problem
 read guides and stuff. this code is just an edited version of a code in the guide.
 
 
 
 Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
 
 
 	  | Turing: |  	  | 
type labelType :
    record 
        name : string (20) 
        link : int
    end record
const  null := 0
const  maxLabels := 100
var  labels : array 1 . . maxLabels of  labelType
var  first :=  null
var  vacant : int := 1
for  i : 1 . . maxLabels - 1 
    labels ( i) .link :=  i + 1
end for
procedure  insert ( newLabel :  labelType)
    assert  vacant not = null
    var  spot :=  vacant
 
    vacant :=  labels ( vacant) .link
 
    labels ( spot) .name :=  newLabel.name
    if  first =  null or  newLabel.name < labels ( first) .name then 
        labels ( spot) .link :=  first
 
        first :=  spot
    else
        var  previous :=  first
        var  next :=  labels ( first) .link
        loop
            exit when  next =  null or 
                newLabel.name < labels ( next) .name
 
            previous :=  next
 
            next :=  labels ( next) .link
        end loop 
        labels ( previous) .link :=  spot
 
        labels ( spot) .link :=  next
    end if
end  insert
procedure  delete ( oldLabel :  labelType)
    var  old : int :=  first
    var  previous : int
    loop
        exit when  old =  null or  labels ( old) .name =  oldLabel.name
 
        previous :=  old
 
        old :=  labels ( old) .link
    end loop
    if  old =  null then
        put  oldLabel.name, "not found"
        return
    elsif  first =  old then 
        first :=  labels ( old) .link
    else 
        labels ( previous) .link :=  labels ( old) .link
    end if 
    labels ( old) .link :=  vacant
 
    vacant :=  old
end  delete
procedure  outputList
    var  current :=  first
    loop
        exit when  current =  null
        put  labels ( current) .name : 20 
        current :=  labels ( current) .link
    end loop
end  outputList
var  newLabel, oldLabel :  labelType
loop
    put "Enter name of label to be instered"
    get  newLabel.name
    exit when ( newLabel.name = 'fin') or ( newLabel.name = 'Fin') 
    insert ( newLabel)
end loop
cls 
outputList
loop
    put "Enter name of record to be deleted"
    get  oldLabel.name
    exit when  oldLabel.name = 'no' 
    delete ( oldLabel)
end loop
put "The remaining survivors are:" 
outputList
 | 
 
 
 
 Edit: i got the backup working. i just made a new procedure called backup with the same code as insert and put into a new array. but i notice one thing that is not working as i thought. you cannot put first and last name at one time because it counts it as two names. (labels) and thats not good...
 |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| Sponsor Sponsor
 
  
   |  |   
		|  |   
		| andrew. 
 
 
 
 
 | 
			
				|  Posted: Mon Jan 04, 2010 9:06 pm    Post subject: RE:Circular linked list help |  |   
				| 
 |  
				| Can't you put "get newLabel.name : *"? It should take in the spaces and everything up until 20 characters (because you set it to that). I haven't tried it though, but it should work. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		| imbored 
 
 
 
 
 | 
			
				|  Posted: Mon Jan 04, 2010 9:29 pm    Post subject: RE:Circular linked list help |  |   
				| 
 |  
				| yea i fixed that now thats why i opened a new thread because i totally re-programmed because this program is confusing for me. |  
				|  |  |   
		|  |  |  
	  
		|  |   
		|  |  
 |