Linked List - inserting node

Page 1 of 1

1 Replies - 224 Views - Last Post: 18 February 2013 - 10:23 PM Rate Topic: -----

#1 johngoodman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 05-February 13

Linked List - inserting node

Posted 18 February 2013 - 10:18 PM

I'm trying to create a function that allows insertion anywhere in a linked list...here is what I have so far but it isn't quite working

void llAddAtIndex(LinkedList** ll, char* value, int index) {

  LinkedList* newNode;
 // newNode = (LinkedList*)malloc(sizeof(*newNode));
  newNode = *ll;
  
  if(index == 0){
	newNode->next = newNode;
	newNode = newNode;
	} else {
	LinkedList* n = newNode;
		for(int i = 0; i < index; i++){
			n = n->next;
		}
		newNode->next = n->next;
		n->next = newNode;
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Linked List - inserting node

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 3845
  • View blog
  • Posts: 11,749
  • Joined: 25-December 09

Re: Linked List - inserting node

Posted 18 February 2013 - 10:23 PM

Duplicate, Closed.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1