Implementation of single link list c++

 Implementation of single link list c++


  #include<iostream>

using namespace std;

struct Node{

	int value;

	Node *next;

};

Node *head=NULL;

void insert(int a)

{

	Node *temp = new Node;

	temp->value = a;

	if (head == NULL)

	{

		temp->next = NULL;

		head = temp;

		cout << "Value was null" << endl;

	}

	else

	{

		temp->next = head;

		head = temp;

		cout << "Value is not null" << endl;

	}

}



	void display()

	{

		Node *temp = new Node;

		temp = head;

		while (temp != NULL)

		{

			cout << temp->value << endl;

			temp = temp->next;

		}

	}

int main()

{

	insert(5);

	insert(6);

	insert(7);

	display();

	getchar();

	return 0;

}     

          

       
 

Comments

Popular posts from this blog

Multiple inheritance,friend function and multiple file in oop(object oriented programming)

Concepts of OOP (object oriented programming)

Concepts in c++........