-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.cpp
37 lines (29 loc) · 1019 Bytes
/
search.cpp
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
/**
* Script que apresenta formas de realizar buscas em uma lista ligada.
*
*/
#include <iostream>
#include "linkedlist.h"
using namespace std;
string searchInLinkedList(string pattern, StringNode * list) {
if (list != NULL) {
if (list->content.compare(pattern) == 0) {
string s = "pattern ";
s.append(pattern);
s.append(" found!");
return s;
}
return searchInLinkedList(pattern, list->next);
}
return "pattern not found";
}
int main(void) {
// Buscando os dados em uma lista "sem cabeça"
StringNode * stringNode = new StringNode("Oi", new StringNode("Tchau"));
cout << searchInLinkedList("Oi", stringNode) << endl;
cout << searchInLinkedList("oi", stringNode) << endl;
// Buscando os dados em uma lista "com cabeça"
NodeHead * nodeHead = new NodeHead(stringNode);
cout << searchInLinkedList("Tchau", nodeHead->next) << endl;
cout << searchInLinkedList("Tchauu", nodeHead->next) << endl;
}