how to add to the end of a linked list
class Node {
Object data;
Node next;
Node(Object d,Node n) {
data = d ;
next = n ;
}
public static Node addLast(Node header, Object x) {
// save the reference to the header so we can return it.
Node ret = header;
// check base case, header is null.
if (header == null) {
return new Node(x, null);
}
// loop until we find the end of the list
while ((header.next != null)) {
header = header.next;
}
// set the new node to the Object x, next will be null.
header.next = new Node(x, null);
return ret;
}
}typedef struct node{
int value; //this is the value the node stores
struct node *next; //this is the node the current node points to. this is how the nodes link
}node;
node *append(node *head, int val){
node *tmp = head;
node *createdNode = createNode(val);
while(tmp->next != NULL){
tmp = tmp->next;
}
tmp->next = createdNode;
return head;
}
Also in C:
- char to int c
- concatenate two strings in c
- rakshabandhan 2020
- run a command in cmd with c
- intellij idea
- fopen c
- how to declare multidimensional array in c
- inurl:fiu.edu math faculty
- what is strikethrough in markdown
- matplotlib pyplot legend location
- how to do Employing defensive code in the UI to ensure that the current frame is the most top level window
- vs code turn off formatter
- arduino client disconnect
- lazer codechef
- ubuntu get to local disk
- c \b
- print double with 2 decimals c
- how to make a linked list in c
- c program to arrange numbers in descending order
- print hello world in c
- c check if char is number
- modulation
- pebble scripting Boolean expression
- warning: function returns address of local variable [-Wreturn-local-addr]