[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-seo-685667-105":3,"detail-sidebar-cat-0-en-105":81,"doc-detail-685667-en":130,"doc-similar-685667":162},{"code":4,"msg":5,"data":6},0,"ok",{"site_id":7,"language":8,"slug":9,"title":10,"keywords":11,"description":12,"schema_data":13,"social_meta":74,"head_meta":76,"extra_data":78,"updated_unix":80},105,"en","implementing-singly-linked-list-in-c-struct-and-pointers","Implementing Singly Linked List in C++ - struct and pointers","","Singly linked list implementation in C++ using a struct-based Node and raw pointers. The document provides multiple examples that show node declaration, dynamic allocation with new, initialization of data and next pointers, and connecting nodes to build the list. It also demonstrates appending nodes to the end by traversing from head to the last node, updating head when the list is empty, and printing all stored values by walking from head until next becomes NULL.",{"@graph":14,"@context":73},[15,34,56],{"@type":16,"itemListElement":17},"BreadcrumbList",[18,23,27,31],{"item":19,"name":20,"@type":21,"position":22},"https://docshare.wps.com","Home","ListItem",1,{"item":24,"name":25,"@type":21,"position":26},"https://docshare.wps.com/document/","Document",2,{"item":28,"name":29,"@type":21,"position":30},"https://docshare.wps.com/document/technology/","Technology",3,{"item":32,"name":10,"@type":21,"position":33},"https://docshare.wps.com/document/implementing-singly-linked-list-in-c-struct-and-pointers/685667/",4,{"url":32,"name":10,"@type":35,"image":36,"author":41,"headline":10,"publisher":44,"fileFormat":47,"inLanguage":8,"description":12,"dateModified":48,"datePublished":49,"encodingFormat":47,"isAccessibleForFree":50,"interactionStatistic":51},"DigitalDocument",{"url":37,"@type":38,"width":39,"height":40},"https://docshare.wps.com/thumbnails/implementing-singly-linked-list-in-c-struct-and-pointers/685667.png","ImageObject",300,407,{"name":42,"@type":43},"Rainbow Cat","Person",{"url":19,"name":45,"@type":46},"DocShare","Organization","application/pdf","2026-11-18","2026-11-07",true,{"@type":52,"interactionType":53,"userInteractionCount":55},"InteractionCounter",{"@type":54},"ViewAction",5,{"@type":57,"mainEntity":58},"FAQPage",[59,65,69],{"name":60,"@type":61,"acceptedAnswer":62},"What is the Node structure used for in the implementation?","Question",{"text":63,"@type":64},"The Node struct stores an int data field and a Node* next pointer to reference the next element in the singly linked list.","Answer",{"name":66,"@type":61,"acceptedAnswer":67},"How does appendNode add a value when the list is empty?",{"text":68,"@type":64},"appendNode checks if head is NULL and, if so, sets head to the newly allocated node.",{"name":70,"@type":61,"acceptedAnswer":71},"How are values printed from the list in order?",{"text":72,"@type":64},"displayList starts from head and repeatedly prints curr->data while advancing curr = curr->next until curr becomes NULL.","https://schema.org",{"og:url":32,"og:type":75,"og:title":10,"og:site_name":45,"og:description":12},"article",{"robots":77,"canonical":32},"index,follow",{"doc_id":79,"site_id":7},685667,1794016535,{"code":4,"msg":82,"data":83},"success",[84,88,92,96,100,104,109,114,119,122,126],{"id":22,"doc_module":4,"doc_module_name":25,"category_name":85,"show_sort_weight":86,"slug":87},"Story & Novel",90,"story-novel",{"id":26,"doc_module":4,"doc_module_name":25,"category_name":89,"show_sort_weight":90,"slug":91},"Literature",80,"literature",{"id":33,"doc_module":4,"doc_module_name":25,"category_name":93,"show_sort_weight":94,"slug":95},"Exam",70,"exam",{"id":55,"doc_module":4,"doc_module_name":25,"category_name":97,"show_sort_weight":98,"slug":99},"Comic",60,"comic",{"id":101,"doc_module":4,"doc_module_name":25,"category_name":29,"show_sort_weight":102,"slug":103},6,50,"technology",{"id":105,"doc_module":4,"doc_module_name":25,"category_name":106,"show_sort_weight":107,"slug":108},7,"Healthcare",40,"healthcare",{"id":110,"doc_module":4,"doc_module_name":25,"category_name":111,"show_sort_weight":112,"slug":113},8,"Research & Report",30,"research-report",{"id":115,"doc_module":4,"doc_module_name":25,"category_name":116,"show_sort_weight":117,"slug":118},9,"Religion & Spirituality",20,"religion-spirituality",{"id":117,"doc_module":4,"doc_module_name":25,"category_name":120,"show_sort_weight":117,"slug":121},"World Cup","world-cup",{"id":123,"doc_module":4,"doc_module_name":25,"category_name":124,"show_sort_weight":123,"slug":125},10,"Lifestyle","lifestyle",{"id":127,"doc_module":4,"doc_module_name":25,"category_name":128,"show_sort_weight":55,"slug":129},19,"General","general",{"code":4,"msg":82,"data":131},{"doc_id":79,"user_id":132,"nickname":42,"user_avatar":133,"doc_module":4,"category_id":101,"category_name":29,"doc_title":10,"doc_description":12,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":55,"is_deleted":4,"is_public":22,"is_downloadable":22,"audit_status":22,"page_count":139,"language":140,"language_code":8,"site_id":7,"html_lang":8,"table_of_contents":141,"faqs":142,"seo_title":143,"seo_description":12,"update_tm":80,"read_time":144,"preview_page_count":33,"preview_urls":145},962090769181,"https://ap-avatar.wpscdn.com/davatar_6f874abed73319feea01a86fa6f0fab8","Implementing Singly Linked List in C++ Using struct Example 1: Declarations to create a node and playing with pointers.  \n\\#include \u003Ciostream>  \nusing namespace std;  \nstruct Node  \n{  \nint data;  \nNode *next;  \n};  \nint main()  \n{  \nNode *head=NULL;  \nNode *t;  \nNode *n;  \nn = new Node;  \nn->data = 10;  \nn->next = NULL;  \nhead=n;  \nt=n;  \nn = new Node;  \nn->data = 20;  \nn->next = NULL;  \ncout\u003C\u003Chead->data\u003C\u003Cendl;  \ncout\u003C\u003Chead\u003C\u003Cendl;  \ncout\u003C\u003Ct->data\u003C\u003Cendl;  \ncout\u003C\u003Ct\u003C\u003Cendl;  \ncout\u003C\u003Cn->data\u003C\u003Cendl;  \ncout\u003C\u003Cn\u003C\u003Cendl;  \nhead->next=n;  \ncout\u003C\u003Cn\u003C\u003Cendl;  \nt=t->next;  \ncout\u003C\u003Ct\u003C\u003Cendl;  \n}  \nExample 2: Adding or Appending a Node to the List \\#include \u003Ciostream>  \nusing namespace std;//Declaration to create a nodestruct Node  \n{  \nint data;  \nNode *next;  \n};  \n// define the head pointer and make it points to null Node *head = NULL;  \n// Adding or Appending a Node to the List void appendNode(int value)  \n{  \nNode *n, *curr;  \n// Allocate a new node & store data n = new Node();  \nn->data = value;  \nn->next = NULL;  \n// If there are no nodes in the list // make n the first node if (head==NULL)  \nhead = n;  \nelse // Otherwise, insert newNode at end {  \n// Initialize curr to head of list  \ncurr = head;  \n// Find the last node in the list while (curr->next!= NULL)  \n{  \ncurr = curr->next;  \n}  \n// Insert newNode as the last node curr->next = n;  \n}  \n} int main(){  \nappendNode(2);  \nappendNode(14);  \nappendNode(26);  \nreturn 0;}  \nExample 3: Adding Nodes to the List and then printing them from the beginning until the end.  \n\\#include \u003Ciostream> using namespace std;  \n//Declaration to create a nodestruct Node  \n{  \nint data;  \nNode *next;  \n};  \n// define the head pointer and make it points to null Node *head = NULL;  \n// Adding or Appending a Node to the List void appendNode(int value)  \n{  \nNode *n, *curr;  \n// Allocate a new node & store data n = new Node();  \nn->data = value;  \nn->next = NULL;  \n// If there are no nodes in the list // make n the first node if (head==NULL)  \nhead = n;  \nelse // Otherwise, insert newNode at end {  \n// Initialize curr to head of list  \ncurr = head;  \n// Find the last node in the list while (curr->next!= NULL)  \n{  \ncurr = curr->next;  \n}  \n// Insert newNode as the last node curr->next = n;  \n}  \n}  \n// displaying the list from the beginning void displayList(void)  \n{  \nNode *curr;  \ncurr = head;  \nwhile (curr!=NULL){  \ncout \u003C\u003C curr->data \u003C\u003C endl;  \ncurr = curr->next;  \n}  \n}  \n// main function int main()  \n{ appendNode(2);  \nappendNode(14);  \nappendNode(26); displayList(); return 0;  \n}  \nExample 4: Insertion at the end of the list.  \n\\#include \u003Ciostream> using namespace std;  \n//Declaration to create a nodestruct Node  \n{  \nint data;  \nNode * next;  \n};  \n// define the head pointer and make it points to null Node *head = NULL;  \n// Adding or Appending a Node to the List void appendNode(int value)  \n{  \nNode *n, *curr;  \n// Allocate a new node & store data n = new Node();  \nn->data = value;  \nn->next = NULL;  \n// If there are no nodes in the list // make n the first node if (head==NULL)  \nhead = n;  \nelse // Otherwise, insert newNode at end  \n{  \n// Initialize curr to head of list curr = head;  \n// Find the last node in the list while (curr->next!= NULL)  \n{  \ncurr = curr->next;  \n}  \n// Insert newNode as the last node curr->next = n;  \n}  \n}  \n// displaying the list from the beginning void displayList(void)  \n{  \nNode *curr;  \ncurr = head;  \nwhile (curr!=NULL){  \ncout \u003C\u003C curr->data \u003C\u003C endl;  \ncurr = curr->next;}  \n}  \n// main function int main()  \n{ appendNode(2);  \nappendNode(14);  \nappendNode(26); displayList(); return 0;  \n}","cbCaif7kckuJSvJL","https://ap.wps.com/l/cbCaif7kckuJSvJL","pdf",204760,31,"English","# Implementing a Singly Linked List\n## Node declarations and pointer usage\n## Appending a node to the end\n## Adding nodes and printing the list\n## Insertion at the end","[{\"question\":\"What is the Node structure used for in the implementation?\",\"answer\":\"The Node struct stores an int data field and a Node* next pointer to reference the next element in the singly linked list.\"},{\"question\":\"How does appendNode add a value when the list is empty?\",\"answer\":\"appendNode checks if head is NULL and, if so, sets head to the newly allocated node.\"},{\"question\":\"How are values printed from the list in order?\",\"answer\":\"displayList starts from head and repeatedly prints curr-\\u003edata while advancing curr = curr-\\u003enext until curr becomes NULL.\"}]","Implementing Singly Linked List in C++ - struct and pointers | PDF",78,[146,150,154,158],{"page_no":22,"url":147,"width":148,"height":149},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/824f04bffb855d07d323e312be53e27e.webp",983,1272,{"page_no":26,"url":151,"width":152,"height":153},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/117c85fe7f874ca0cf9fcd0a538e5004.webp",982,1270,{"page_no":30,"url":155,"width":156,"height":157},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/64d906248891f0ea2582c77d02cf6fa0.webp",981,1269,{"page_no":33,"url":159,"width":160,"height":161},"https://res-academy.cache.wpscdn.com/upload/kdocshare/2026-11-09/687f0f13190175280f356449785a4c8d.webp",980,1268,{"list":163,"token":11},[164,170,176,182,188,194,200,206,212,218],{"doc_id":165,"doc_title":166,"file_type":137,"home_preview_img_url":167,"slug":168,"view_count":30,"category_name":29,"create_tm":169},732873,"Singly Linked Lists in C - Introduction and Traversal Example","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230031413508/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=aiHC5ieA60wPK9SHR0ffCqIoeW0%3D","singly-linked-lists-in-c-introduction-and-traversal-example",1795382670,{"doc_id":171,"doc_title":172,"file_type":137,"home_preview_img_url":173,"slug":174,"view_count":101,"category_name":29,"create_tm":175},685766,"Linked Lists - Fundamentals - Core Concepts and C++ Implementation Notes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000198068/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=dZzRiuAy01Yu9DauedNtbhjpchs%3D","linked-lists-fundamentals-core-concepts-and-c-implementation-notes",1794017949,{"doc_id":177,"doc_title":178,"file_type":137,"home_preview_img_url":179,"slug":180,"view_count":105,"category_name":29,"create_tm":181},685731,"Lecture Five - Linked List Structure","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999689386/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=6LBqbwvYA2WebmWgoN%2B%2Ff0P6jG8%3D","lecture-five-linked-list-structure",1794017204,{"doc_id":183,"doc_title":184,"file_type":137,"home_preview_img_url":185,"slug":186,"view_count":105,"category_name":29,"create_tm":187},685760,"CS62 Class 8 - Linked lists - Basic Data Structures","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000192614/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=FTE1yqlet7ErMC3OQEemIAQoeYQ%3D","cs62-class-8-linked-lists-basic-data-structures",1794017629,{"doc_id":189,"doc_title":190,"file_type":137,"home_preview_img_url":191,"slug":192,"view_count":55,"category_name":29,"create_tm":193},685726,"L6b - Linked List Variations - Lecture 6b","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000185855/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=cyah91ewrAIZwwhrphvMUYq%2BYOg%3D","l6b-linked-list-variations-lecture-6b",1794017196,{"doc_id":195,"doc_title":196,"file_type":137,"home_preview_img_url":197,"slug":198,"view_count":55,"category_name":29,"create_tm":199},685741,"ROHINI COLLEGE OF ENGINEERING & TECHNOLOGY - Linked list implementation - Singly linked lists - Core algorithms for traversal, counting, searching and insertion","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000186201/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=eUS5qZmrsZeOvQYSscOQa7khHK4%3D","rohini-college-of-engineering-technology-linked-list-implementation-singly-linked-lists-core-algorithms-for-traversal-counting-searching-and-insertion",1794017223,{"doc_id":201,"doc_title":202,"file_type":137,"home_preview_img_url":203,"slug":204,"view_count":30,"category_name":29,"create_tm":205},719597,"Chapter 15 - Linked Data Structures - Java Linked Lists - Key Concepts","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230023815525/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=YX7PxomIULgS8zFaHrVPhAsuL3g%3D","chapter-15-linked-data-structures-java-linked-lists-key-concepts",1795006731,{"doc_id":207,"doc_title":208,"file_type":137,"home_preview_img_url":209,"slug":210,"view_count":55,"category_name":29,"create_tm":211},685762,"Linked List - Course 13004700 Part-2","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110229999691129/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=jK2tAKMHRckPrfhTux%2FhMvButgM%3D","linked-list-course-13004700-part-2",1794017631,{"doc_id":213,"doc_title":214,"file_type":137,"home_preview_img_url":215,"slug":216,"view_count":33,"category_name":29,"create_tm":217},685736,"Singly Linked List in C - C Program - Linked List Operations Menu","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230000186160/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=YBwT8WI6zvH3SWnhA0tsEKjda4s%3D","singly-linked-list-in-c-c-program-linked-list-operations-menu",1794017213,{"doc_id":219,"doc_title":220,"file_type":137,"home_preview_img_url":221,"slug":222,"view_count":26,"category_name":29,"create_tm":223},719605,"Linked Lists - lecture notes","https://weboffice-temporary-prod-sg.obs.ap-southeast-3.myhuaweicloud.com:443/export/thumbnail/export/thumbnail/110230023815899/last/300/407?AWSAccessKeyId=HPUAE6OPDRI9QZXR6WJG&Expires=1796111999&Signature=A%2FUUm9qDHybuKosEzlvUFd5He78%3D","linked-lists-lecture-notes",1795006752]