nt_trung92 Thành viên
Tổng số bài gửi : 24 Votes : 0 Join date : 14/09/2011
| Tiêu đề: Ai giúp tớ cái danh sách liên kết với khó wa Sat Sep 24, 2011 8:58 pm | |
| Consider the following definition for a linked list. Note that you have to devise of a way to test all of your implemented functions. typedef struct Node ListNode; struct Node{ int data; ListNode *next; } typedef struct FirstNode *LinkedList; struct FirstNode{ ListNode *first; } 1. Write a function to create a new list from a file where all space-separated numbers are shown on the first line: LinkedList newList(char *filename){ } 2. Write a function to create a new node containing the value v: // Create a new node containing a given number ListNode newListNode(int v){ } 3. Write the implementation for the following functions: //print out the elements in the list void printList(LinkedList l){ } //add a new number to the beginning of the listvoid addFirst(LinkedList l, int v){ } //add a new number to the end of the list void addLast(LinkedList l, int v){ } //remove the first element in the list void removeFirst(LinkedList l){ } //Find the first index of a given element in the list. //The first element has index 0. // -1 if v is not in the list int findIndex(LinkedList l, int v){ thanks | |
|
Admin Admin
Tổng số bài gửi : 80 Votes : 7 Join date : 14/09/2011 Age : 32 Đến từ : Hải Dương, Việt Nam
| Tiêu đề: Re: Ai giúp tớ cái danh sách liên kết với khó wa Sat Sep 24, 2011 10:02 pm | |
| Ý của ông là gì? Dịch chỗ này ra tiếng Việt á Còn nếu chỉ là danh sách liên kết thì tôi có thể giúp dc chút ít... | |
|
salonpas Thành viên
Tổng số bài gửi : 1 Votes : 0 Join date : 25/09/2011
| Tiêu đề: Re: Ai giúp tớ cái danh sách liên kết với khó wa Sun Sep 25, 2011 12:34 am | |
| - Code:
-
#include <iostream> #include <fstream> #include <conio.h> using namespace std; // danh sach lien ket fstream fin("khoa.in", ios :: in); struct Node { int data; Node *next; }; Node *head = new Node; // create a new integer list void tao1nut(Node *node,int value) { node->data = value; node->next = NULL; } Node* taodanhsach() { int tmp; fin >>tmp; head->data = tmp; head->next = NULL; if(!fin.good()) { cerr <<"file's wrong!\n"; return NULL; } Node *tail = head; while(!fin.eof()) { fin >>tmp; Node *cur = new Node(); tao1nut(cur,tmp); tail->next = cur; tail = cur; } return head; } // in list void in() { Node *cur = head; while(cur != NULL) { cout <<cur->data<<" "; cur = cur->next; } cout <<endl; } // xoa dau danh sach void xoadau() { Node *newHead = head; head = head->next; delete newHead; } // them cuoi void themcuoi(int n) { Node *tail = new Node(); tao1nut(tail,n); Node*cur = head; while(cur->next != NULL) cur = cur->next; cur->next = tail; } // them dau void themdau(int n) { Node *newHead = new Node(); tao1nut(newHead,n); newHead->next = head; head = newHead; } // xoa phan tu mang gia tri value void xoavalue(int value) { Node *cur = head; Node *pre = new Node(); while(cur != NULL) { if(cur->data == value) { if(cur == head) xoadau(); else{ Node *p = cur; pre->next = cur->next; cur = cur->next; delete p; } } else{ pre = cur; cur = cur->next; } } } int main() { taodanhsach(); in(); xoadau(); in(); themcuoi(100); themdau(9); in(); xoavalue(4); in(); getch(); return 0; } co bai nay co ban bac doc thu xem | |
|
nt_trung92 Thành viên
Tổng số bài gửi : 24 Votes : 0 Join date : 14/09/2011
| Tiêu đề: Re: Ai giúp tớ cái danh sách liên kết với khó wa Mon Sep 26, 2011 10:21 am | |
| thanks nhiều nha có bài của ông tôi dọc thấy dễ hiểu chứ đọc giáo trình nó viết lung tung wa | |
|
Sponsored content
| Tiêu đề: Re: Ai giúp tớ cái danh sách liên kết với khó wa | |
| |
|