-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedlist.h
56 lines (40 loc) · 1.81 KB
/
linkedlist.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//filename: linkedlist.h - version 1
//In the version 1 of our implementation, we'll represent a
//linked list as just a pointer to the first node
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
using namespace std;
struct Node{
string data;
Node* next; //self-referencing
};
// function that adds a node to the front of list
// Precondition: @param head stores a valid linked list
// @param value is a string
// Postcondition: Add a new node with data value to the front of the list
// returns the new list
Node* addToFrontOfList(Node* head, string value);
// Precondition: @param head stores a valid linked list
// @param value is a string
// Postcondition: Add a new node with data value to the front of the list
// and update the head parameter to hold the address of the new list
// void addToFrontOfList(Node*& head, string value);
void printList(Node* head);
// append a node to the list
// how can we pass a linkedlist as a parameter to a function
//IMPORTANT: In all the functions, each node in the linked-list may only
//contain a STRING data (NOTE: The linkedlist we are implementing is different
//from the one in the CS16-Final exam Q3 (warmup lab) where each node stored
//a single character)
//All functions below have been modified accordingly
//Precondition: The address of a valid LinkedList and a string
//Postcondition: Adds a new node with data element set to value to the
//end of the linked list.
//void addToEndOfList(LinkedList*& list, string value);
//Precondition: A string array with a given length
//Postcondition: The address of a new LinkedList containing all the
//characters of the input array in the same order, where each node of
//the linked list contains one element of the array.
//LinkedList* arrayToLinkedList(string* arr, int len);
#endif