Algorithm 搜索列表中x.key=k的所有元素

Algorithm 搜索列表中x.key=k的所有元素,algorithm,list,search,Algorithm,List,Search,我需要搜索列表中x.key=k的所有元素x。我将创建一个空列表G,其中存储有关索引的信息 search(L,G,k) x <- L.head y <- G.head i <- 0 while (x.next != null) x <- x.next i <- i+1 if(x.key = k) y.next <- new y y &l

我需要搜索列表中x.key=k的所有元素x。我将创建一个空列表G,其中存储有关索引的信息

search(L,G,k)
    x <- L.head
    y <- G.head
    i <- 0
    while (x.next != null)
        x <- x.next
        i <- i+1
        if(x.key = k)
            y.next <- new y
            y <- y.next
            y.key <- i
搜索(L、G、k)

x我要做一些更正:

 while (x != null)
        if(x.key = k)
            do some stuff with y
        i <- i+1
        x <- x.next
while(x!=null)
如果(x.key=k)
和我一起做些事情
我