![]() |
|
|
Регистрация Восстановить пароль |
Повторная активизация e-mail |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
![]() |
|
Опции темы | Поиск в этой теме |
![]() |
#1 |
Новичок
Джуниор
Регистрация: 22.12.2007
Сообщений: 1
|
![]()
#include <iostream.h>
#include <fstream.h> #include <math.h> #include <string.h> class List { private: struct Node { string key; int code; Node *next; } * head; public: List(); ~List(); void Add( int code, string value); void LoadFromFile( string file_name); void SaveToFile( string file_name); void PrintToScreen(); void Sort(); void Clear(); bool operator = (List ); }; List::List() { head = NULL; } void List::Add( int code, string value) { Node *newNode = new Node; newNode->key = value; newNode->code = code; newNode->next = head; head = newNode; } void List::LoadFromFile( string file_name) { ifstream fin; fin.open(file_name.data()); Clear(); string str; int code; while (1) { fin >> code >> str; if (fin.eof()) break; Add(code, str); } fin.close(); } void List::SaveToFile( string file_name) { ofstream fout; fout.open(file_name.data()); Node *t; t = head; while (t) { fout << t->code << " " << t->key << endl; t = t->next; } fout.close(); } void List::PrintToScreen() { Node * currentNode; currentNode = head; while (currentNode) { cout << "code: " << currentNode->code << "; string = " << currentNode->key << endl; currentNode = currentNode->next; } } bool List: ![]() { Node *NodeList1 = head; Node *NodeList2 = list.head; while ((NodeList1) || (NodeList2)) { if ((NodeList1->key != NodeList2->key) && (NodeList1->code != NodeList2->code)) return false; NodeList1 = NodeList1->next; NodeList2 = NodeList2->next; } return true; } void List::Sort() { Node *p, *q, *m; p = head; string st; int ct; while (p) { q = p; m = p; while (q) { if (m->key.length() < q->key.length()) m = q; q = q->next; } st = m->key; m->key = p->key; p->key = st; ct = m->code; m->code = p->code; p->code = ct; p = p->next; } } void List::Clear() { Node *currentNode, *next; currentNode = head; while (currentNode) { next = currentNode->next; delete currentNode; currentNode = next; } head = NULL; } List::~List() { Clear(); } int main() { List list1; string s; int n, code; cout << "Input number of records: "; cin >> n; for (int i = 0; i < n; ++i) { cout << "Input code and string: "; cin >> code >> s; list1.Add(code, s); } list1.SaveToFile("List 1.txt"); list1.LoadFromFile("List 1.txt"); list1.Sort(); list1.SaveToFile("Sorted list 1.txt"); return 0; } /* Файлы для хранения данных создаются в папке с программой */ |
![]() |
![]() |
![]() |
#2 |
ИСККОНный хакер
Форумчанин
Регистрация: 08.11.2007
Сообщений: 195
|
![]()
См. приват.
#define QUESTION bb || !bb
|
![]() |
![]() |
![]() |
Опции темы | Поиск в этой теме |
![]() |
||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
Что нужно сделать, чтобы форма была поверх панели задач? | Andr | Общие вопросы Delphi | 11 | 25.02.2011 22:06 |
Help плиз! Нужно перевести текст в программу!!! | XzB | Помощь студентам | 1 | 07.06.2008 11:54 |
Помогите прокомментировать прогу | Astor | Помощь студентам | 2 | 20.05.2008 21:28 |
Помогите плиз с 2-мя задачами нужно до среды | Perf | Паскаль, Turbo Pascal, PascalABC.NET | 2 | 22.01.2008 16:35 |
Здравствуйте! Помогите пожалуйста, нужно написать планировщик задач. | perple | Помощь студентам | 1 | 19.10.2007 19:37 |