Home › Forums › C Programming › SOS!!!
- This topic has 4 replies, 2 voices, and was last updated 16 years, 4 months ago by GeoffreyBeeler.
- AuthorPosts
- August 23, 2008 at 2:09 am #2127GeoffreyBeelerParticipant
pls help me…
i don’t know what to do…
who can send source code…
Phone book sorter
The objective is to create an application pbsorter that sorts phonebook entries in ascending order. A phonebook entry is made of a word and a number separated by a comma. Each entry is separated by a newline. An example of unsorted phonebook entries:Villar,90912345
Arroyo,91855661
Lacson,91681233pbsorter can be executed in 2 ways. Suppose the above entries are stored in a file pbook.csv, if we want to sort by name:
./pbsorter -a pbook.csv
The new pbook.csv entries will be:Arroyo,91855661
Lacson,91681233
Villar,90912345If we want to sort by number:
./pbsorter -n pbook.csv
The new pbook.csv entries will be:Villar,90912345
Lacson,91681233
Arroyo,91855661Use getopt to parse the option. Use available sorting functions in the library to perform sorting.
- August 24, 2008 at 9:03 am #3422HumayanParticipant
What type of data structure are you supposed to enter the items into ( a linked list , array ) ? What type of sort are you to use?
- August 24, 2008 at 11:57 pm #3423GeoffreyBeelerParticipant
linked list, any kind of sorting but preferrably binary search tree…
can you do it asap,,? i need this tomorrow….if only….thanks.. - August 25, 2008 at 5:34 am #3424HumayanParticipant
I have this binary seach tree ( hope this helps ) :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249/*<br />* Název programu: ADT Binarni strom<br />* Autor: Petr Bobek<br />* Studijnà skupina: IT-01<br />* Email autora: [email protected]<br />* Datum vypracovánÃ: 26.10.2005<br />* Stručný popis řeÅ¡enÃ: Je uveden dale v programu<br />*/<br />#include "iostream"<br />#include "stdio.h"<br />#include "conio.h"<br />#include "malloc.h"<br />#include "process.h"<br />#include "stdlib.h"<br />#include "string.h" //standardnà knihovny<br />using namespace std;<br />typedef char tStr;<br />struct uzel<br />{<br />int item;<br />struct uzel *right;<br />struct uzel *left;<br />};<br />typedef struct uzel * BST;<br />typedef struct uzel uzel;<br />bool Empty ( BST t )<br />{<br />if( t != NULL )<br />return false;<br />else<br />return true;<br />}<br />void Initialize ( BST * t )<br />{<br />* t = NULL;<br /><br />}<br />void DeleteTree ( BST t )<br />{<br />if ( t != NULL )<br />{<br />DeleteTree ( t-> left );<br />DeleteTree ( t->right );<br />free ( t );<br />}<br />}<br />BST Search ( BST t, int x )<br />{<br />if( t == NULL )<br />{<br />cout << "item was not found!" << endl;<br />return NULL;<br />}<br />if( x < t -> item )<br />{<br />return Search( t -> left , x );<br />}<br />else if( x > t -> item )<br />return Search ( t -> right , x );<br />else<br />return t;<br /><br />}<br />BST Insert ( BST * t, int x )<br />{<br />if( * t == NULL )<br />{<br />* t = (struct uzel * ) malloc ( sizeof ( struct uzel ) );<br />(* t ) -> item = x;<br />( * t ) -> left = ( * t ) -> right = NULL;<br />return * t;<br />}<br /><br />if( ( *t ) -> item > x)<br />Insert ( & ( ( * t ) -> left ) , x );<br />else<br />Insert ( & ( ( * t ) -> right ) , x );<br /><br /><br />}<br />BST findmin ( BST t )<br />{<br /><br />while ( t -> left )<br />t = t -> left;<br />return t;<br /><br />}<br />BST findmax ( BST t )<br />{<br />while ( t -> right )<br />t = t -> right;<br />return t;<br /><br />}<br />void removeMin ( BST * t )<br />{<br />while ( ( * t ) -> left )<br />( * t ) = ( * t ) -> left;<br /><br />BST temp = * t;<br />* t = ( ( * t ) -> right );<br />free ( temp );<br /><br />}<br />//THIS DOESN'T LOOK RIGHT<br />BST Delete ( BST * t, int x )<br />{<br />BST pom_bunka;<br />if( t == NULL )<br />{<br />cout << " Cannot delete, bin. tree is empty !"<< endl;<br />return NULL;<br />}<br />if ( x < ( * t ) -> item )<br />Delete ( & ( ( * t ) -> left ) , x );<br />else if ( x > ( * t ) -> item )<br />Delete ( & ( ( * t ) -> right ) , x ); <br />else if ( ( * t ) -> right != NULL && ( * t ) -> left != NULL )<br />{<br />BST temp = findmin ( ( * t ) -> right );<br />( * t ) -> item = temp -> item;<br />removeMin ( & (( * t ) -> right ) );<br />}<br />else<br />{<br />BST temp = * t ;<br />if ( ( * t ) -> left != NULL )<br />* t = ( * t ) -> left;<br />else<br />* t = ( * t ) -> right;<br />free ( temp );<br />}<br />}<br />void Preorder ( BST t )<br />{<br />if ( t != NULL )<br />{<br />cout << t -> item << endl;<br />Preorder ( t -> left );<br />Preorder ( t -> right ) ;<br />}<br /><br /><br />}<br />void Inorder ( BST t )<br />{<br />if ( t != NULL )<br />{<br />Inorder ( t -> left );<br />cout << t -> item << endl;<br />Inorder ( t -> right );<br />}<br />}<br />void Postorder ( BST t )<br />{<br />if ( t != NULL )<br />{<br />Postorder ( t -> left );<br />Postorder ( t -> right );<br />cout << t -> item << endl;<br />}<br />}<br />int getData ( void )<br />{<br /><br />cout << "Get data: ";<br />int data;<br />cin >> data;<br />return data;<br />}<br />/*<br />void VypisSeznam(BST t){<br />tStr data;<br />cout << "Obsah seznamu:";<br />if (Empty(t)==true){<br />cout<<" NULL"<<endl;<br />}<br />else{<br />data = t->item;<br />cout << data << ", ";<br />}<br />}<br />*/<br />void Menu ( void )//vypis menu<br />{<br />cout << "nGet number 0-7: nn";<br />cout << "0: Inicializen";<br />cout << "1: Insertn";<br />cout << "2: Searchn";<br />cout << "3: Preordern";<br />cout << "4: Inordern";<br />cout << "5: Postordern";<br />cout << "6: Deleten";<br />cout << "7: Delete treen";<br />cout << "M: Menun";<br />cout << "E: Endn";<br />}<br />int main()<br />{<br /><br />char znak;<br />BST strom = 0 ; //root ?<br />int data;<br />//tStr data;<br />do {<br />Menu();<br />cout << "nnEnter Choice ! >> ";<br />cin >> znak;<br />switch ( toupper ( znak ) )<br />{<br />case '0' : cout << "Inicialize - inicializuje stromn";<br />Initialize ( & strom );<br />//VypisSeznam(strom);<br />break;<br />case '1' : cout << "Insert - vlozi do stromu novy uzeln";<br />cout << "Get data: ";<br />cin >> data;<br />Insert( & strom , data );<br />//VypisSeznam(strom);<br />break;<br />case '2' : cout << "Search - vyhleda uzeln";<br />Search(strom, getData());<br />cout<<strom<<endl;<br />break;<br />case '3' : cout << "Preorder - projde strom pruchodem preordern";<br />Preorder(strom);<br />break;<br />case '4' : cout << "Inorder - projde strom pruchodem inordern";<br />Inorder(strom);<br />break;<br />case '5' : cout << "Postorder - projde strom pruchodem postordern";<br />Postorder(strom);<br />break;<br />case '6' : cout << "Delete - smaze ze stromu uzeln";<br />Delete( & strom, getData());<br />break;<br />case '7' : cout << "Delete Tree - smaze cely stromn";<br />DeleteTree(strom);<br />break;<br />case 'M' : Menu();<br />break;<br />case 'E' :<br />break;<br />default : cout << "Zadali jste nespravny znak!!!n";<br />}<br />} while (toupper(znak) != 'E');<br />return 0;<br />} - August 25, 2008 at 6:17 pm #3425GeoffreyBeelerParticipant
thanks..
that helped a lot…
hoping for replies again next time…
thank you very much….
- AuthorPosts
- The forum ‘C Programming’ is closed to new topics and replies.