You are on page 1of 4

Nama : Soniya Jasmine Azzahra

NRP : 2210191029

Kelas : 1 D4 TK A

Grub 3

Codingan :
#include <bits/stdc++.h>

#include <assert.h>

#include<stdio.h>

#include<string.h>

#include<iostream>

using namespace std;

class Node {

public:

float data;

Node* next;

};

void push(Node** head_ref, float new_data) {

Node* new_node = new Node();

new_node->data = new_data;

new_node->next = (*head_ref);

(*head_ref) = new_node;

int getCount(Node* head) {

if (head == NULL) return 0;

return 1 + getCount(head->next);

float GetNth(Node* head, int index) {

Node* current = head;

int count = 0;

while (current != NULL) {


if (count == index)

return(current->data);

count++;

current = current->next;

assert(0);

int sumOfNodes(struct Node* head)

struct Node* ptr = head;

int sum = 0;

while (ptr != NULL) {

sum += ptr->data;

ptr = ptr->next;

return sum;

int GetPosition(Node* head, float value) {

Node* current = head;

int count = 0;

while (current != NULL) {

if (current->data == value) {

cout << "\nalamat linked list nya " << value << "adalah " << current << endl;

cout << "\nNilai node 4 : " << count << endl;

return 0;

// return(count);

count++;

current = current->next;
}

assert(0);

void printList(struct Node* node) {

while (node != NULL) {

printf(" %.1f ", node->data);

node = node->next;

int main() {

Node* head = NULL;

push(&head, 4);

push(&head, 1);

push(&head, 12);

push(&head, 1);

push(&head, 6);

push(&head, 9);

push(&head, 2);

push(&head, 7);

push(&head, 2);

push(&head, 3);

cout << "List Node : ";

printList(head);

printf("\nnode ke : 0 1 2 3 4 5 6 7 8 9");

cout << "\n\njumlah Lisked List : " << getCount(head) << endl;

cout << "\nNilai node ke 7 : " << GetNth(head, 7) << endl;

GetPosition(head, 4);

return 0;

}
Output :

You might also like