Home › Forums › C Programming › Can You Help Me Plz!
- This topic has 5 replies, 2 voices, and was last updated 16 years, 4 months ago by kanwar.
- AuthorPosts
- August 12, 2008 at 2:45 am #2121kanwarParticipant
Im just hoping that this room will actualy help me so much. Hm, Im Roldan of Philippines still studying Computer Enginnering and we’re given task to make a data structure program that has a menu and in menu.. we can have a choice to select options by which each option realy have huge size of programming codes.
Like Array of LInked List, how should i put that program in the whole fuse program in the menu. Plz help me how to do this. For more clarrification, here is an output illustration:
/ ****MENU*****
Press:1 to insert node at the beginning.
2 to insert node at the middle.
3 to delete the node.
4 for array of linked list
5 for doubly link list
6. for circularly linked list
7 append linked list
8 to exit./so plz me here. Send me best websites that will give best and fit answers for my problem. Hope you can help me here.. The core of my problem is the concept of fusing or inserting the huge programs like circularly in a one program…
Thank you and Godbless
Plz do replies coz i need it this week! - August 12, 2008 at 10:40 am #3414HumayanParticipant
Heres some code I found on my hard drive :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121#include<iostream.h><br />//simple list<br />struct node<br />{<br />int i;<br />node * next;<br />};<br />void print ( node * );<br />void addBack ( int , node *& , node *& );<br />void addFront ( int , node *& , node *& );<br />void destroy ( node *& );<br />void main()<br />{<br />node * head = NULL;<br />node * tail = NULL;<br />char choice;<br />int i;<br />do<br />{<br />cout << "choose an operation: " << endl;<br />cout << "1. add a node to back of list" << endl;<br />cout << "2. add a node to front of list" << endl;<br />cout << "3. print the list. " << endl;<br />cout << "4. exit " << endl;<br />cin >> choice;<br />cin.get();<br />cout << endl;<br />switch ( choice )<br />{<br />case '1':<br />{<br />cout << " enter an integer : " ;<br />cin >> i;<br />addBack ( i , head , tail );<br />};<br />break;<br />case '2':<br />{<br />cout << " enter an integer : " ;<br />cin >> i;<br />addFront ( i , head , tail );<br />};<br />break;<br />case '3':<br />{<br />print ( head );<br />};<br />break;<br />case '4':<br />{<br />cout <<"goodbye!" << endl;<br />};<br />break;<br />default: cout << "bad choice !" << endl;<br /><br />};<br />cout << endl;<br />}<br />while ( choice != '4' );<br />destroy ( head ); <br /><br /><br />}<br />void print ( node * r )<br />{<br />node * t = r;<br />cout << "This is the list: " << endl;<br /><br />while ( t != NULL )<br />{<br />cout << " " << t -> i << " ";<br />t = t -> next;<br />}<br />cout << endl;<br />}<br />void addBack ( int n , node *& h , node *& t )<br />{<br />if ( h == NULL )<br />{<br />h = t = new node;<br />t -> i = n;<br />t -> next = NULL;<br />}<br />else<br />{<br /><br />t -> next = new node;<br />t -> next -> i = n;<br />t -> next -> next = NULL;<br />t = t -> next;<br /><br />}<br />}<br />void addFront ( int n , node *& h , node *& t )<br />{<br />if ( h == NULL ) //empty list<br />{<br /><br />h = t = new node;<br />t -> i = n;<br />t -> next = NULL;<br />}<br />else //add to front<br />{<br />node * temp = h;<br /><br />h = new node;<br />h -> i = n;<br />h -> next = temp;<br />}<br />}<br />void destroy ( node *& h )<br />{<br />node * temp;<br />while ( h != NULL )<br />{<br />temp = h;<br />h = h -> next;<br />delete temp;<br />}<br />} - August 13, 2008 at 11:32 am #3415HumayanParticipant
Heres a quick translation into c:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127#include < stdlib.h ><br />#include < stdio.h ><br />//simple list<br />typedef struct nodeType<br />{<br />int i;<br />struct nodeType * next;<br />} node;<br />void print ( node * );<br />void addBack ( int , node ** , node ** );<br />void addFront ( int , node ** , node ** );<br />void destroy ( node ** );<br />void main()<br />{<br />node * head = NULL;<br />node * tail = NULL;<br />char choice;<br />char newline;<br />int i;<br />do<br />{<br />printf ( "choose an operation: n" );<br />printf ( "1. add a node to back of list n" );<br />printf ( "2. add a node to front of list n" );<br />printf ( "3. print the list. n" );<br />printf ( "4. exit n" );<br />choice = getchar ();<br />newline = getchar ();<br />printf ( "n" );<br />switch ( choice )<br />{<br />case '1':<br />{<br />printf ( "enter an integer : n" );<br />scanf ( "%d",& i );<br />addBack ( i , & head , & tail );<br />newline = getchar ();<br />};<br />break;<br />case '2':<br />{<br />printf ( "enter an integer : n" );<br />scanf ( "%d",& i );<br />addFront ( i , & head , & tail );<br />newline = getchar ();<br />};<br />break;<br />case '3':<br />{<br />print ( head );<br />};<br />break;<br />case '4':<br />{<br />printf ( "goodbye! n" );<br />};<br />break;<br />default: printf ( "bad choice ! n" );<br /><br />};<br />printf ( "n" );<br />}<br />while ( choice != '4' );<br />destroy ( & head ); <br /><br /><br />}<br />void print ( node * r )<br />{<br />node * t = r;<br />printf ( "This is the list: n" );<br /><br />while ( t != NULL )<br />{<br />printf ( "%c" ," " );<br />printf ( "%i" , t -> i );<br />printf ( "%c" , " " );<br />t = t -> next;<br />}<br />printf ( "n" );<br />}<br />void addBack ( int n , node ** h , node ** t )<br />{<br />if ( ( * h ) == NULL )<br />{<br />( * h ) = ( * t ) = malloc ( sizeof ( node ) );<br />( * t ) -> i = n;<br />( * t ) -> next = NULL;<br />}<br />else<br />{<br /><br />( * t ) -> next = malloc ( sizeof ( node ) );<br />( * t ) -> next -> i = n;<br />( * t ) -> next -> next = NULL;<br />( * t ) = ( * t ) -> next;<br /><br />}<br />}<br />void addFront ( int n , node ** h , node ** t )<br />{<br />if ( ( * h ) == NULL ) //empty list<br />{<br /><br />( * h ) = ( * t ) = malloc ( sizeof ( node ) );<br />( * t ) -> i = n;<br />( * t ) -> next = NULL;<br />}<br />else //add to front<br />{<br />node * temp = ( * h );<br /><br />( * h ) = malloc ( sizeof ( node ) );<br />( * h ) -> i = n;<br />( * h ) -> next = temp;<br />}<br />}<br />void destroy ( node ** h )<br />{<br />node * temp;<br />while ( ( * h ) != NULL )<br />{<br />temp = ( * h );<br />( * h ) = ( * h ) -> next;<br />free ( temp );<br />}<br />} - August 28, 2008 at 7:13 pm #3416kanwarParticipant
Mr Cman how can I insert the stack programs in the menu programs that I asked u last time?
- August 29, 2008 at 9:41 am #3417HumayanParticipant
You want to add a stack to the program? Heres a stack I wrote for another project:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330/****************************************************************<br />* File Name : c:programshelpshell.cpp<br />* Date : December,26,2007<br />* Comments : new project<br />* Compiler/Assembler :<br />* Program Shell Generated At: 3:08:45 p.m.<br />=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /><br />#include < iostream ><br />//#include < string.h ><br />//#include < conio.h ><br />//#include < math.h ><br />//#include < iomanip ><br />//#include < ctype.h ><br />using namespace std;<br />struct stackNode<br />{<br />fretNode * current;<br />fretNode * first;<br />fretNode * last;<br />int repeats;<br />stackNode * next;<br />};<br />struct stateNode<br />{<br />fretNode * fp;<br />fretNode * cp;<br />fretNode * cfp;<br />fretNode * cbp;<br />stackNode * cs;<br />stackNode * fs;<br />stateNode * next;<br />};<br /><br /><br />//>>>>>>>>>>>>>>>>>>>>>>>> GLOBAL DATA <<<<<<<<<<<<<<<<<<<<<<<<<<br />bool stackError = false;<br />//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<br /><br />//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@<br />bool push ( stackNode *& stack , fretNode * current , fretNode * first , fretNode * last , int repeats );<br />bool pop ( stackNode *& stack );<br />void clear ( stackNode *& stack );<br />bool copy ( stackNode *& destination , stackNode * source );<br />// stackNode * clone ( stackNode * stackToClone );<br />bool pushState ( stateNode *& stack , fretNode * currentPattern , fretNode * currentFrontPattern , fretNode * currentBackPattern , stackNode * currentStack , stackNode * frontStack );<br />bool popState ( stateNode *& stack , fretNode *& currentPattern , fretNode *& currentFrontPattern , fretNode *& currentBackPattern , stackNode *& currentStack , stackNode *& frontStack );<br />void clear ( stateNode *& stack );<br />bool copy ( stateNode *& destination , stateNode * source );<br />void setState ( stateNode *& stack , fretNode *& currentPattern , fretNode *& currentFrontPattern , fretNode *& currentBackPattern , stackNode *& currentStack , stackNode *& frontStack );<br />//##################################################################################<br /><br /><br />/******************************* FUNCTION DEFINITION ******************************<br />Name : push<br />Parameters :<br />current a(n) fretNode * ( fretNode * ) ,<br />first a(n) fretNode * ( fretNode * ) ,<br />last a(n) fretNode * ( fretNode * ) ,<br />repeats a(n) int<br /><br />Returns: Void type<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool push ( stackNode *& stack , fretNode * current , fretNode * first , fretNode * last , int repeats )<br />{<br />stackNode * s = new stackNode;<br />if ( ! s )<br />{<br />stackError = true;<br />return false;<br />}<br />s -> current = current;<br />s -> first = first;<br />s -> last = last;<br />s -> repeats = repeats;<br />s -> next = stack;<br />stack = s;<br /><br />return true;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br />Name : pop<br />Parameters :<br />void<br /><br />Returns: Void type<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool pop ( stackNode *& stack )<br />{<br />if ( stack )<br />{<br />stackNode * temp = stack;<br />stack = stack -> next;<br />delete temp;<br /><br />return true;<br />}<br />return false;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br />Name : clear<br />Parameters :<br />void<br /><br />Returns: Void type<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void clear ( stackNode *& stack )<br />{<br />stackNode * temp;<br /><br />while ( stack )<br />{<br />temp = stack;<br />stack = stack -> next;<br />delete temp;<br />}<br />stack = 0;<br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br />Name : copy<br />Parameters :<br />destination a(n) stackNode * ( stackNode * ) ,<br />source a(n) stackNode ( stackNode )<br /><br />Returns: user defined type , bool<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool copy ( stackNode *& destination , stackNode * source )<br />{<br />int i = 0;<br />stackNode * last = 0;<br /><br />destination = 0;<br /><br />while ( source )<br />{<br />stackNode * s = new stackNode;<br />if ( ! s )<br />{<br />stackError = true;<br />return false;<br />}<br />if ( i == 0 )<br />{<br />destination = s;<br />i ++;<br />}<br />if ( last )<br />last -> next = s;<br /><br /><br />s -> current = source -> current;<br />s -> first = source -> first;<br />s -> last = source -> last;<br />s -> repeats = source -> repeats;<br />s -> next = 0;<br />last = s;<br />source = source -> next;<br />}<br /><br />return true;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br />Name : pushState<br />Parameters :<br />stack a(n) stateNode *& ( stateNode *& ) ,<br />frontPattern a(n) stateNode * ( stateNode * ) ,<br />currentPattern a(n) stateNode * ( stateNode * ) ,<br />currentFrontPattern a(n) stateNode * ( stateNode * ) ,<br />currentBackPattern a(n) stateNode * ( stateNode * ) ,<br />currentStack a(n) stackNode * ( stackNode * ) ,<br />frontStack a(n) stackNode * ( stackNode * )<br /><br />Returns: user defined type , bool<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool pushState ( stateNode *& stack , fretNode * currentPattern , fretNode * currentFrontPattern , fretNode * currentBackPattern , stackNode * currentStack , stackNode * frontStack )<br />{<br /><br />stateNode * s = new stateNode;<br />if ( ! s )<br />{<br />stackError = true;<br />return false;<br />}<br /><br />// s -> fp = frontPattern;<br />s -> cp = currentPattern;<br />s -> cfp = currentFrontPattern;<br />s -> cbp = currentBackPattern;<br />copy ( s -> cs , currentStack );<br />copy ( s -> fs , frontStack );<br />s -> next = stack;<br />stack = s;<br /><br />return true;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br />Name : popState<br />Parameters :<br />stack a(n) stackNode * ( stackNode * ) ,<br />frontPattern a(n) stateNode *& ( stateNode *& ) ,<br />currentPattern a(n) stateNode *& ( stateNode *& ) ,<br />currentFrontPattern a(n) stateNode *& ( stateNode *& ) ,<br />currentBackPattern a(n) stateNode *& ( stateNode *& ) ,<br />currentStack a(n) stackNode *& ( stackNode *& ) ,<br />frontStack a(n) stackNode *& ( stackNode *& )<br /><br />Returns: user defined type , bool<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool popState ( stateNode *& stack , fretNode *& currentPattern , fretNode *& currentFrontPattern , fretNode *& currentBackPattern , stackNode *& currentStack , stackNode *& frontStack )<br />{<br />if ( stack == 0 )<br />{<br />return false;<br />}<br /><br />// frontPattern = stack -> fp;<br />currentPattern = stack -> cp;<br />currentFrontPattern = stack -> cfp;<br />currentBackPattern = stack -> cbp;<br />currentStack = stack -> cs;<br />frontStack = stack -> fs;<br />stack = stack -> next;<br /><br />return true;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br />Name : clear<br />Parameters :<br />void<br /><br />Returns: Void type<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void clear ( stateNode *& stack )<br />{<br />stateNode * temp;<br /><br />while ( stack )<br />{<br />temp = stack;<br />stack = stack -> next;<br />clear ( temp -> cs );<br />clear ( temp -> fs );<br />delete temp;<br />}<br />stack = 0;<br />return;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br />Name : copy<br />Parameters :<br />destination a(n) stackNode * ( stackNode * ) ,<br />source a(n) stackNode ( stackNode )<br /><br />Returns: user defined type , bool<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />bool copy ( stateNode *& destination , stateNode * source )<br />{<br />int i = 0;<br />stateNode * last = 0;<br /><br />destination = 0;<br />while ( source )<br />{<br />stateNode * s = new stateNode;<br />if ( ! s )<br />{<br />stackError = true;<br />return false;<br />}<br />if ( i == 0 )<br />{<br />destination = s;<br />i ++;<br />}<br />if ( last )<br />last -> next = s;<br /><br />//s -> fp = source -> fp;<br />s -> cp = source -> cp;<br />s -> cfp = source -> cfp;<br />s -> cbp = source -> cbp;<br />copy ( s -> cs , source -> cs );<br />copy ( s -> fs , source -> fs );<br />s -> next = 0;<br />last = s;<br />source = source -> next;<br />}<br /><br />return true;<br />}<br />/******************************* FUNCTION DEFINITION ******************************<br />Name : setState<br />Parameters :<br />stack a(n) stateNode *& ( stateNode *& ) ,<br />currentPattern a(n) fretNode *& ( fretNode *& ) ,<br />currentFrontPattern a(n) fretNode *& ( fretNode *& ) ,<br />currentBackPattern a(n) fretNode *& ( fretNode *& ) ,<br />currentStack a(n) stackNode *& ( stackNode *& ) ,<br />frontStack a(n) stackNode *& ( stackNode *& )<br /><br />Returns: user defined type , void<br />Comments:<br /><br />++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/<br />void setState ( stateNode *& stack , fretNode *& currentPattern , fretNode *& currentFrontPattern , fretNode *& currentBackPattern , stackNode *& currentStack , stackNode *& frontStack )<br />{<br />currentPattern = stack -> cp;<br />currentFrontPattern = stack -> cfp;<br />currentBackPattern = stack -> cbp;<br />currentStack = stack -> cs;<br />frontStack = stack -> fs;<br />return;<br />} - September 5, 2008 at 6:28 pm #3418kanwarParticipant
fREN, i know u know file handling..! we got difficulty in our file handling. We have the search,create account,browse but we dont know how to update our account! How is that Mr Cman!
- AuthorPosts
- The forum ‘C Programming’ is closed to new topics and replies.