開発環境
- OS X Mavericks - Apple, ときどき
Windows 8.1 + Cygwin64, MinGW (OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- C++ (プログラミング言語)
- g++(コンパイラ)
C++実践プログラミング (スティーブ オウアルライン (著)、Steve Oualline (原著)、Steve Oualline(原著)、望月 康司(翻訳)、クイープ(翻訳) 、オライリー・ジャパン)のⅣ部(高度なプログラミング概念)の20章(高度なポインタ)、20.3(リンクリスト)、設問 20-1.を解いてみる。
その他参考書籍
- C++プログラミング入門 (グレゴリー サティア (著)、ダウグ ブラウン (著)、Gregory Satir (原著)、Doug Brown (原著)、望月 康司 (翻訳)、谷口 功 (翻訳)、オライリージャパン)
設問 20-1.
コード(BBEdit, Emacs)
find.cpp
#include <string>
#include "linked.h"
bool linked_list::find(const std::string& data)
{
linked_list_element *current_ptr;
current_ptr = first_ptr;
// 順序を逆にする
while ((current_ptr != NULL) && (current_ptr->data != data))
current_ptr = current_ptr->next_ptr;
return current_ptr != NULL;
}
test_find.cpp
#include <iostream>
#include <string>
#include "linked.h"
int main(int argc, char *argv[])
{
linked_list ll;
std::string names[] = {"kamimura", "cpp", "c++"};
int i;
ll.add_list("kamimura");
ll.add_list("cpp");
for (i = 0; i < 3; ++i) {
std::cout << names[i] << ": " << ll.find(names[i]) << std::endl;
}
return (0);
}
Makefile
CC=g++
CFLAGS=-g -Wall
all: test_find
test_find: test_find.cpp find.o
${CC} ${CFLAGS} -o test_find test_find.cpp find.o
find.o: find.cpp linked.h
${CC} -c -o find.o find.cpp
clean:
rm test_find
入出力結果(Terminal)
$ make && ./test_find g++ -c -o find.o find.cpp g++ -g -Wall -o test_find test_find.cpp find.o kamimura: 1 cpp: 1 c++: 0 $
0 コメント:
コメントを投稿