linkedlist implementation in c++

#include <iostream>

using namespace std;

struct node
{
    int data;
    node *next;
};

class linked_list
{
private:
    node *head,*tail;
public:
    linked_list()
    {
        head = NULL;
        tail = NULL;
    }

    void add_node(int n)
    {
        node *tmp = new node;
        tmp->data = n;
        tmp->next = NULL;

        if(head == NULL)
        {
            head = tmp;
            tail = tmp;
        }
        else
        {
            tail->next = tmp;
            tail = tail->next;
        }
    }
};

int main()
{
    linked_list a;
    a.add_node(1);
    a.add_node(2);
    return 0;
}

3.5
2

                                    
#include &lt;bits/stdc++.h&gt;
#include &lt;iostream&gt;
#include &lt;list&gt;
#include &lt;iterator&gt;

#define ll long long

using namespace std;

//function to print all the elements of the linked list
void showList(list &lt;int&gt; l){
	list &lt;int&gt; :: iterator it; //create an iterator according to the data structure
	for(it = l.begin(); it != l.end(); it++){
		cout&lt;&lt;*it&lt;&lt;&quot; &quot;;
	}
	
}	


int main(){
	
	list &lt;int&gt; l1;
	list &lt;int&gt; l2;
	
	for(int i=0; i&lt;10; i++){
		l1.push_back(i*2); //fill list 1 with multiples of 2
		l2.push_back(i*3); //fill list 2 with multiples of 3
	}
	
	cout&lt;&lt;&quot;content of list 1 is &quot;&lt;&lt;endl;
	showList(l1);
	cout&lt;&lt;endl;
	
	cout&lt;&lt;&quot;content of list 2 is &quot;&lt;&lt;endl;
	showList(l2);
	cout&lt;&lt;endl;
	
	//reverse the first list
	l1.reverse();
	showList(l1);
	cout&lt;&lt;endl;
	
	//sort the first list
	l1.sort();
	showList(l1);
	cout&lt;&lt;endl;
	
	//removing an element from both sides
	l2.pop_front();
	l2.pop_back();
	
	//adding an element from both sides
	l2.push_back(10);
	l2.push_front(20);
	
	
    return 0;
}

3.5 (2 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
linked list in c+ linked list in c++ cpp creating a linked list in cpp stl linked list c++ code learn implementing a linked list in c++ linkedlist using class c/++ linked lists in cpp stl linked list design in c++ include linked list c++ linked list using functions in cpp linked list stl in c++ linkedi list using cpp how to implement a linked list in c++ linked list c+= implement linked list in c++ using struct c++ linked list operations code linkedlist lib c++ linked list simple program in c++ linked list on c++ linked list in c++ algorithms linked list in c++ algorithm linked list c++ programs class based implementation in c++ linked list linked list in cpp using struct linked list in c++ program examples linked list inin c++ implemented linked list using c++ cpp linked list implementation class creating linked list in c++ using struct linked lists class implementation c++ struct c++ linked list c++ classic linked list implementation linked list c++ data structure linkedl list code in c++ linked list operations in c++ linked list exam in c++ linked list c++ Linked list implementation in c++ example linked lists in stl linked list using c++ stl linkedlist using structure in c++ linked list c++ struct does cpp jave linked list library? linked list in c+= linked list declaration cpp STL linked lists using c++ what is stl linked list in c++ linked list c++ class implementation string linked list in c++ linked list c++ linkedlist cpp linked list implementation using class in c++ linked list struct C++ linked list c++ reference linked list c++ program linked list in stl c++ linked list c++ this linkedlist c++ this linked list c++ stl singlt c++ linked list standard library understanding linked list c++ linked list in c++ using struct linked list creation in c++ is list in c++ stl a doubly linked link list using c++ what are the built in functions for STL linked list cpp implementation linked list c++ stl linked list c++ does list in c++ is linkedlist STL linked list in Cpp link list c+ linkd list in cpp linked list inc++ linkedlist in cpp linked list stl in cpp linkedlist implementation in c++ using class linked list program in cpp C++ std library linked list show a linked list c++ stl c+++ linked list linked list tutorial c++ where to use a linked list c++ linked list using stl linked list in cpp stl c++ linked list tutorial how to make linked list in cpp c++ linkedlist stl basic linked-list functions c++ create linked list in c++ c++ linked list list linked list c++ linked list class cpp linked lists on linked list c++ define linked list in c++ linked list c++ METHODS linked list in linked list c++ general linked list c++ linked list implementation with struct c++ linked list c++ example linked list c++ functions linkked list using c++ struct implementation of linked list in c++ c++ linked list std linked list c++ standard library c++ implementation of linked list node of linked list stl c++ linked list for c++ linked list of linked lists c++ linked list implementation in array in c++ c++ using linked list stl c++ using linked list linked list in c++ implementation of linked list using c++ linked list operations c++ how to define linked list c++ linked list stl c++ linked list using struct c++ c++ linked list built in linked list using stl in c++ linked list design c++ what is a linked list in c++ implementation class c++ using singly linked list implementation class c++ using linked list linkedlist stl cpp define linked list in c++ programming std::linked list c++ c ++ linked list linked list cpp code c/cpp linked list how to implement linked list in cpp linked list library C++ linked list c++ library linked list of string in c++ c++ linked list linked list using stl c++ initializer list constructor for doubly linked list c++ initializer list constructor linked list c++ linker in c++ linked list structures in c linked list linkedlist in cpp stl linked list in c++ implementation linked list.cpp basic linked list program in c++ linked lists implementation in c++ linkedi list c++ linkedlist implementation using c++ Linked list in stl linked list class implementation c++ linked list built in cpp linkedlist in stl implement linked list c++ linked list syntax c++ linked list based list c++ simple c++ linked list link list implementation in cpp linked lists in c++ data structures linkedlist class implementation in c++ linked list in c++ program linked list in c++ stl linked list in c++; c++ doubly linked list stl linked list c++ stl c++ stl linked list linked list programs in c++ list implementation as linked list c++ linked list C++ std how to include linked list in c++ simple linked list program in c++ linkedlist example c++ does c++ have a linked list linked list in C ++ creating a linked list using stl in cpp linked list struct in c++ how to use linked list stl in c++ how to use linked list in c++ linkeded list in c++ linked list algorithm in c++ linked list program in c++ using struct implementation of linked list in cpp linked list syntax in c++ linked list program c++ implementing linked list in cpp linked list methods in c++ linked list in c++ program with explanation c++ linked list library c++ linked list no unordered list in C++ linked list adt c++ c++ code to create a linked list Link List c++ COd c++ code for dynamic linked list linked list with many courses c++ c++ example linked list c++ example linked listg c++ linked list example program link list in cpp how to declare node in c++ linked list functions in c++ how to fill a singly linked list cpp how to get linked list in cpp linked list c++ full code list in vector c++ slt using stl to implement linked list list in stl list functions in c++ list inc++ linked list library in cpp implrement linked list in c++ making linked list in c++ address of the class node in cpp linked list program in c++ list library cpp list library c++ class node c++ simple int node c++ list functions c++ c++ implement linked list linked list implementation in c+ linked list pseudocode c++ list int in c++ linked list STL cpp implementation of stack adt using linked list in c++ set linked list in c++ c++ linked list n node implements a linked list in c++ cpp singe linked list stl cpp linked list stl linked list in c++ stl pop function c++ library for linked list list list c++ one way linked list c++ how to use stl list code for linked list in c++ making a linked list in c++ with stl useing list in c++ singly linmked list in c++ stl linked list create node cpp creating ll in cpp linked list in c++ code Implement a one-way link list singly linked list in c++ how to loop through a linked list cpp linked set c++ stl lis create singly linked list in cpp using single pointers linked list program in c++ using stl c++ linked list program doubly linked list in cpp implementation linked list simple code linked list stl tree implementation linked list c++ linked list stl linked list in cpp implementation list c++ functions linked list c+ what is list in c++ stl what is linked list in c++ contoh program linked list c++ what is list stl in c++ use &lt;&lt; for linked list c++ linkedhashset in c++ linked list implementation of graph single linked list c++ how to make a linked list c++ singly linked list of objects in c++ how to use list in c++ create singly linked list in c++ singly list of class c++ implementation your own list stl in c++ implementation of list stl in c++ using class implementation of linked list in c++ using class show element linked list in c++ search in linked list c++ linked list implementation of queue linnked list in cpp the functions of linked list c++ linked list using cpp how to store the head node in c++ C++ struct node algorithm for singly linked list c++ how to write linked list linked list diagram c++ linked-list uses linked list c++ using structs c++ list example list of stl c++ linked list code linked list data structure c++ code lined list code c++ lists in cpp linked list c++ operations make a list in c similar to std::list linked list c++ class example c++ stl doubly linked list user defined linked list in c++ by class user defined linked list in c++ c++ linked list example code list of int c++ implementation code int list c++ implementation code how to make linked list in c++ cpp list list get in c++ list stl cpp linked listin cpp linked list in cpp stl cplusplus struct for doubly linked list c++ c++ list access elements of list in c++ list in c++ how to create linked list in cpp how to make a linked list class in c++ is std list linked list in c++ c++ list stl what data type does list make in c++ inked list cpp list methods in c++ cpp list type list c++[] how to make class into linked list C++ how to access data in linked list cpp list c++ std list linked list c++ with class mplement the destructor, Append, and Print methods of the linked list data structure using C++ here. c++ make head linked list function in c++ implement singly linked list adt linked list in c++ class create a linked list in c++ what is linklist data structure c++ linked lists cpp c++ list implementation example c++ linked list print function in list library implement a list with node c++ whast is linked list in c++ making a linked list class with a node struct singly linked list of node cpp node and list classes cpp singly linked list class cpp linked list c ++ creating a linked list c++ code of linklist through pointer in c++ linked list in c++ oop linked list of classes c++ linked list c++ generation create a node c++ write a code to insert at begining of linklist in data structure oop write a code to insert at start of linklist in data structure oop linked list display tail c++ linked list example in c++ class based linked list c++ is in list in linked list c++ linked list c++ classes linked list implementation c++ using pointer LinkedList.cpp c++ linked list class implementation how to create a node in c++ linked list c++ class linked list basic in cpp why is head pointer of a linked list initialised within a different class c++ how to give a pointer of a linked list in cpp Linked List Node c++ linkedlist class in c++ source code linkedlist class in c++ creating linked list c++ linked list class in c++ linked list() c++ linked list using new c++ example code with linked lists cpp c++ link list c++ linked list info creation of a linked list in c++ list data structure in c++ C++ linked lists how to create a node implementing a linked list in cpp code of integer type linked list in c++ c++ linked list class example create linked list first node a function cpp create linked list firs node cpp linked list in c++ link list operation in c++ linkd list c++ create linked list c++ c++ linked based list linked-based list. c++ Creation of linked list c++ creating a linked list in c++ linked list implementation in cpp singly linked list in c++ using class linked list implementation c++ classes implementation of linked list c++ c++ connect linkned lists linked list using class in c++ accessing linked list using function c++ linked chain c++ c++ linked list. linkded list c ++ how to create a new node in main classes ?c++ c++ program to create a linked list of n number of nodes c++ creating new node from class how to create linked list in c++ implement linked list in c++ using class list data structure c++ singly link list implementation C++ cpp storing struct in linked list does c++ have a linked list class linked list has one, and only one value stored in it? c++ cpp linked list implementation singly linked list implementation c++ using linked list in c++ create a linked list c++ linedlist in c++ c++ linked lists linked list implementation C++ without classes implementing linked list in c++ insertion in linked list in c++ program at tail class c++ linked list class linked list using struct in c++ c++ node struct linkedlist c++ c++ 2 class use same linked list linkedilist c++ singly linked list constructor c++ linked list with c++ linked list c++ code exampl linked lost in c++ linked list class c++ c++ linkedlist class c++ list implementation linkedlist c++4 how to make a linked list in c++ linked c++ how to make a linked list in c++ linked list in c++ using class One Link in a linked list c++ Linked Lists c++ at function Linked Lists c++ creating node in c++ using list library in c++ print linked list class implementation of linked list in c++ linked list made easy c++ structures and linked lists in c++ cpp linked list creating node c++ c++ linked list\ createing a linked list in c++ creating a linked list of n in cpp linked list example c++ link list functions in c++ storing elements using linked list c++ c++ singly linked list linked list using c++ linked lists using pointers in c++ linked list code cpp linked list example in c[pp how to create a linked list in c++ linked list in cpp\ how to create a linkedlist in c++ linked list constructor c++ linked lists in c++ implement linked list in c++ how to implement linked list in c++ create a linked list in cpp LinkedList implementation c++ creating anode c++ creating a node in c++ how to define a node in c++ cpp linked class c++ linkedlist linklist in c++ linked list c++ code linked list code in c++ implement linked list cpp linked list cpp return a linked list c++ means LinkedList n c++\ how to implement list in c+++ linkedlist in c++ creating linked list in c++ linked lsit c++ singly linked list in cpp using class complete linked list implementation in c++ linked list c++ implementation link list in c++ linked lists in cpp linked list in cpp linked list in c++ singly linked list functions c++ how to create asingly linked list c++ linkedilist in c++ working with linked lists cpp how to take input in a struct node in c++ priority queue in c++ implementation c++ dynamic array implementation singly linked list cpp cpp create a linked list create a linked list cpp linked list using classes in c++ How to create a Linked LIst C++ using struct How to create a Linked LIst C++ create node function in c+ linked list function cpp link list c++ how to write linked list in c++ singly linked list c++ using 2 class singly linked list c++ what is a linked list cpp create a singly linked list in c++ create node function C++ create list of linked list c++ single item linked list c++ c++ linked list linked list in c++ example with headarrray linked list in c++ example c++ linked list example definiton of linked list c++ c++ linked list implementation linked list c++ node in link list c++ liled list implementation c++ linked list implementation c++ linked list implementation in c++ linkedlist implementation in c++
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source