Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Linked List - inserting node

$
0
0
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;
	}
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>