Search
 
SCRIPT & CODE EXAMPLE
 

CPP

print linked list recursively c++

/*
  follow me: https://codejudge.blogspot.com/
*/

#include<iostream>
using namespace std;

struct node
{
	int data;
	node* next;
};
node* insert(node* head, int value)
{
	node* temp1 = (node*)malloc(sizeof(node));
	temp1->data = value;
	temp1->next = NULL;
	if (head == NULL)
	{
		head = temp1;
	}
	else
	{
		node* temp2 = head;
		while (temp2->next!=NULL)
		{
			temp2 = temp2->next;
		}
		temp2->next = temp1;
	}
	return head;
}
void print(node* p)
{
	if (p == NULL)
		return;
	cout << p->data << " ";
	print(p->next);
}
int main()
{
	node* head = NULL;
	head = insert(head, 1);
	head = insert(head, 2);
	head = insert(head, 3);
	print(head);

	return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ check if string contains non alphanumeric 
Cpp :: how to sort a vector in descending order in c++ 
Cpp :: how to make a hello world program in c++ 
Cpp :: save all output in log file c cpp 
Cpp :: c++ vector iterator 
Cpp :: clang cpp compile command 
Cpp :: extends c++ 
Cpp :: c++ random 
Cpp :: heap buffer overflow c++ 
Cpp :: how to make a n*n 2d dynamic array in c++ 
Cpp :: cpp mst 
Cpp :: c++ memory leak 
Cpp :: find in set of pairs using first value cpp 
Cpp :: c++ get time 
Cpp :: c++ extend class 
Cpp :: gfgdf 
Cpp :: chrono start time in c++ 
Cpp :: c++ how to make a negative float positive 
Cpp :: how to make calculaor in c++ 
Cpp :: c++ std::sort 
Cpp :: c++ get full line of input 
Cpp :: change integer to string c++ 
Cpp :: include cpp 
Cpp :: how to convert string into lowercase in cpp 
Cpp :: vector size for loop 
Cpp :: Xor implementation C++ 
Cpp :: stoi cpp 
Cpp :: c++ keyboard input 
Cpp :: loop through array c++ 
Cpp :: for loop f# 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =