Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Bitnami MediaWiki
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
4165 – FinserareKX
(section)
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Rezolvare== <syntaxhighlight lang="python" line> #4165 FInserareKX class Node: def __init__(self, info): self.info = info self.next = None def FInserareKX(head, k, x): new_node = Node(x) # Cazul în care lista este inițial vidă sau inserăm la începutul listei if head is None or k <= 1: new_node.next = head head = new_node return head # Cazul în care lista are cel puțin un nod și inserăm pe poziția k sau la sfârșitul listei current = head prev = None count = 1 while current and count < k: prev = current current = current.next count += 1 if current is None: # Inserare la sfârșitul listei prev.next = new_node else: # Inserare pe poziția k new_node.next = current prev.next = new_node return head # Funcție pentru afișarea listei def afisare_lista(head): current = head while current: print(current.info, end=" ") current = current.next print() # Exemplu de utilizare if __name__ == "__main__": # Inițializare lista cu câteva noduri head = Node(1) head.next = Node(2) head.next.next = Node(3) head.next.next.next = Node(4) head.next.next.next.next = Node(5) # Inserare pe poziția k = 3 a valorii x = 100 head = FInserareKX(head, 3, 100) # Afișare lista rezultată afisare_lista(head) </syntaxhighlight>
Summary:
Please note that all contributions to Bitnami MediaWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Bitnami MediaWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width