Skip to content

Week4_Allen_Simmons#105

Open
asimmo65 wants to merge 3 commits intoBlue-movement:masterfrom
asimmo65:master
Open

Week4_Allen_Simmons#105
asimmo65 wants to merge 3 commits intoBlue-movement:masterfrom
asimmo65:master

Conversation

@asimmo65
Copy link
Copy Markdown

#Allen Simmons
#Week 4

"""
Given a Linked List which represents a sentence S such that each node
represents a letter, the task is to reverse the sentence without reversing
individual words.

  • Ex.)
    Input: I-> ->l->o->v->e-> ->G->e->e->k->s-> ->f->o->r-> ->G->e->e->k->s->NULL
    Output: G->e->e->k->s-> ->f->o->r-> ->G->e->e->k->s-> ->l->o->v->e-> ->I->NULL
    """

def reverse(S):
list1 = ""
length = len(S) - 1

print(length)

for position in range(length, -1,-1):
    #print(position)
    list1 =  list1 +  S[position]
    #print(list)

return list1

S = [" I ", " love ", " Geeks ", " for ", " Geeks "]
#my code doesn't use stacks or queues, it reads the length of 6 -1 = 5.
#set list1 equal to list1 + the item in the index position, looped.

print(reverse(S))

@7daylenrobertson
Copy link
Copy Markdown
Contributor

Check your slack I have a few comments :)

asimmo65 added 2 commits July 24, 2020 14:35
pushed spaces and letters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants