Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- typedef struct linked_list {
- int value{};
- linked_list* next = nullptr;
- } linked_list;
- void insert_last(linked_list* &head, int new_value) {
- if (head==nullptr) {
- linked_list *k = new linked_list();
- k->value=new_value;
- head=k;
- } else {
- linked_list *act = head;
- while (act->next != nullptr) {
- act=act->next;
- }
- linked_list *elem = new linked_list();
- elem->value=new_value;
- act->next = elem;
- }
- }
- void print_ll (linked_list *head) {
- while (head!=nullptr) {
- cout<<head->value<<" ";
- head=head->next;
- }
- }
- int main() {
- linked_list *head = nullptr;
- insert_last(head, 1);
- insert_last(head, 2);
- insert_last(head, 3);
- print_ll(head);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement