Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
Estoy pasando Object como referencia a una función y haciendo algunos cambios, pero el objeto permanece sin cambios.

Estoy implementando una Lista Enlazada y dentro de una función estoy cambiando el encabezado con algún otro elemento de la Lista Enlazada, que aparece correctamente dentro de esa función cuando hago console.log pero fuera de esa función cuando hago console.log e iterativamente imprimo el valor de los datos, la cabeza permanece sin cambios y el elemento con el que cambié la cabeza no se imprime

 ## My implementation of linked list export class Node<T = number> { public get data(): T { return this._data; } public set data(v: T) { this._data = v; } public next: Node<T> | null = null; constructor(private _data: T) {} } export default class LinkedList<T = number> implements ILinkedList<T> { static fromArray<T>(array: Array<T>): LinkedList<T> { const ll = new LinkedList<T>(); for (let i = array.length - 1; i >= 0; i--) { ll.insertInBegin(array[i]); } return ll; } print(): void { let current = this.head; while (current.next !== null) { console.log(current.data); current = current.next; } console.log(current.data); } public head: Node<T> | null = null; #size: number = 0; public get size(): number { return this.#size; } insertInBegin(data: T): Node<T> { const newNode = new Node(data); newNode.next = this.head; this.head = newNode; this.#size++; return newNode; } } ### This is what i want to do function partition(head: Node | null, x: number): Node | null { let current = head.next; head.next = current.next; current.next = head; head = current; console.log('Inside parititon:head', head); // Inside parititon:head Node { // _data: 4, // next: Node { _data: 7, next: Node { _data: 3, next: [Node] } } // } return head; } const a = LinkedList.fromArray([7, 4, 3, 2, 5, 2]); console.log('Before partition'); // Before partition // 7 // 4 // 3 // 2 // 5 // 2 a.print(); partition(a.head, 3); console.log('Outside head:', a.head); // Outside head: Node { // _data: 7, // next: Node { _data: 3, next: Node { _data: 2, next: [Node] } } // } a.print(); // 7 // 3 // 2 // 5 // 2
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!