Home Forums C Programming Can You Help Me Plz!

Viewing 5 reply threads
  • Author
    Posts
    • #2121
      kanwar
      Participant

      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!

    • #3414
      Humayan
      Participant

      Heres some code I found on my hard drive :
       

      #include
      //simple list
      struct node
      {
       int i;
       node * next;
      };
      void print ( node * );
      void addBack ( int , node *&  , node *& );
      void addFront ( int , node *& , node *& );
      void destroy ( node *& );
      void main()
      {
       node * head = NULL;
       node * tail = NULL;
       char choice;
       int i;
       do
       {
        cout << "choose an operation: " << endl;
        cout << "1. add a node to back of list" << endl;
        cout << "2. add a node to front of list" << endl;
        cout << "3. print the list. " << endl;
        cout << "4. exit " << endl;
        cin >> choice;
        cin.get();
        cout << endl;
        switch ( choice )
        {
         case '1':
         {
          cout << " enter an integer : " ;
          cin >> i;
          addBack ( i , head , tail );
         };
         break;
         case '2':
         {
          cout << " enter an integer : " ;
          cin >> i;
          addFront ( i , head , tail );
         };
         break;
         case '3':
         {
          print ( head );
         };
         break;
         case '4':
         {
          cout <<"goodbye!" << endl;
         };
         break;
         default: cout << "bad choice !" << endl;
        
        };
        cout << endl;
       }
       while ( choice != '4' );
       destroy ( head ); 
       
       
      }
      void print ( node * r )
      {
       node * t = r;
       cout << "This is the list: " << endl;
       
       while ( t != NULL )
       {
        cout << " " << t -> i << " ";
        t = t -> next;
       }
       cout << endl;
      }
      void addBack ( int n , node *& h  , node *& t )
      {
       if ( h == NULL )
       {
        h = t = new node;
        t -> i = n;
        t -> next = NULL;
       }
       else
       {
        
        t -> next = new node;
        t -> next -> i = n;
        t -> next -> next = NULL;
        t = t -> next;
       
       }
      }
      void addFront ( int n , node *& h , node *& t )
      {
       if ( h == NULL ) //empty list
       {
        
        h = t = new node;
        t -> i = n;
        t -> next = NULL;
       }
       else //add to front
       {
        node * temp = h;
        
        h = new node;
        h -> i = n;
        h -> next = temp;
       }
      }
      void destroy ( node *& h )
      {
       node * temp;
       while ( h != NULL )
       {
        temp = h;
        h = h -> next;
        delete temp;
       }
      }
    • #3415
      Humayan
      Participant

      Heres a quick translation into c:
       

      #include < stdlib.h >
      #include < stdio.h >
      //simple list
      typedef struct nodeType
      {
       int i;
       struct nodeType * next;
      } node;
      void print ( node * );
      void addBack ( int , node **  , node ** );
      void addFront ( int , node ** , node ** );
      void destroy ( node ** );
      void main()
      {
       node * head = NULL;
       node * tail = NULL;
       char choice;
       char newline;
       int i;
       do
       {
        printf ( "choose an operation: n" );
        printf ( "1. add a node to back of list n" );
        printf ( "2. add a node to front of list n" );
        printf ( "3. print the list. n" );
        printf ( "4. exit n" );
        choice = getchar ();
        newline = getchar ();
        printf ( "n" );
        switch ( choice )
        {
         case '1':
         {
          printf ( "enter an integer : n" );
          scanf ( "%d",& i );
          addBack ( i , & head , & tail );
          newline = getchar ();
         };
         break;
         case '2':
         {
          printf ( "enter an integer : n" );
          scanf ( "%d",& i );
          addFront ( i , & head , & tail );
          newline = getchar ();
         };
         break;
         case '3':
         {
          print ( head );
         };
         break;
         case '4':
         {
          printf ( "goodbye! n" );
         };
         break;
         default: printf ( "bad choice ! n" );
        
        };
        printf ( "n" );
       }
       while ( choice != '4' );
       destroy ( & head ); 
       
       
      }
      void print ( node * r )
      {
       node * t = r;
       printf ( "This is the list: n" );
       
       while ( t != NULL )
       {
        printf ( "%c" ," " );
        printf ( "%i" , t -> i );
        printf ( "%c" , " " );
        t = t -> next;
       }
       printf ( "n" );
      }
      void addBack ( int n , node ** h  , node ** t )
      {
       if ( ( * h  ) == NULL )
       {
        ( * h ) = ( * t ) = malloc ( sizeof ( node ) );
        ( * t ) -> i = n;
        ( * t ) -> next = NULL;
       }
       else
       {
        
        ( * t ) -> next = malloc ( sizeof ( node ) );
        ( * t ) -> next -> i = n;
        ( * t ) -> next -> next = NULL;
        ( * t ) = ( * t ) -> next;
       
       }
      }
      void addFront ( int n , node ** h , node ** t )
      {
       if ( ( * h ) == NULL ) //empty list
       {
        
        ( * h ) = ( * t ) = malloc ( sizeof ( node ) );
        ( * t ) -> i = n;
        ( * t ) -> next = NULL;
       }
       else //add to front
       {
        node * temp = ( * h );
        
        ( * h ) = malloc ( sizeof ( node ) );
        ( * h ) -> i = n;
        ( * h ) -> next = temp;
       }
      }
      void destroy ( node ** h )
      {
       node * temp;
       while ( ( * h ) != NULL )
       {
        temp = ( * h );
        ( * h ) = ( * h ) -> next;
        free ( temp );
       }
      }
    • #3416
      kanwar
      Participant

      Mr Cman how can I insert the stack programs in the menu programs that I asked u last time?

    • #3417
      Humayan
      Participant

      You want to add a stack to the program? Heres a stack I wrote for another project:
       

      /****************************************************************
      * File Name : c:programshelpshell.cpp
      * Date : December,26,2007
      * Comments : new project
      * Compiler/Assembler :
      * Program Shell Generated At: 3:08:45 p.m.
      =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/

      #include < iostream >
      //#include < string.h >
      //#include < conio.h >
      //#include < math.h >
      //#include < iomanip >
      //#include < ctype.h >
      using namespace std;
      struct stackNode
      {
       fretNode * current;
       fretNode * first;
       fretNode * last;
       int repeats;
       stackNode * next;
      };
      struct stateNode
      {
          fretNode * fp;
          fretNode * cp;
          fretNode * cfp;
          fretNode * cbp;
          stackNode * cs;
          stackNode * fs;
          stateNode * next;
      };
       

      //>>>>>>>>>>>>>>>>>>>>>>>> GLOBAL DATA <<<<<<<<<<<<<<<<<<<<<<<<<
          bool stackError = false;
      //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
       
      //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ FUNCTION PROTOTYPES @@@@@@@@@@@@@@@@@@@@@@@@@@
       bool push  ( stackNode *& stack , fretNode * current , fretNode * first , fretNode * last , int repeats );
       bool pop   ( stackNode *& stack );
       void clear ( stackNode *& stack );
       bool copy ( stackNode *& destination , stackNode * source );
         // stackNode * clone ( stackNode * stackToClone );
          bool pushState ( stateNode *& stack , fretNode * currentPattern , fretNode * currentFrontPattern , fretNode * currentBackPattern , stackNode * currentStack , stackNode * frontStack );
          bool popState ( stateNode *& stack , fretNode *& currentPattern , fretNode *& currentFrontPattern , fretNode *& currentBackPattern , stackNode *& currentStack , stackNode *& frontStack );
       void clear ( stateNode *& stack );
       bool copy ( stateNode *& destination , stateNode * source );
          void setState ( stateNode *& stack , fretNode *& currentPattern , fretNode *& currentFrontPattern , fretNode *& currentBackPattern , stackNode *& currentStack , stackNode *& frontStack );
      //##################################################################################
       

      /******************************* FUNCTION DEFINITION ******************************
       Name : push
       Parameters :
        current a(n) fretNode * ( fretNode * )  ,
        first a(n) fretNode * ( fretNode * )  ,
        last a(n) fretNode * ( fretNode * )  ,
        repeats a(n) int

       Returns: Void type
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      bool push ( stackNode *& stack , fretNode * current , fretNode * first , fretNode * last , int repeats )
      {
          stackNode * s = new stackNode;
          if ( ! s )
          {
              stackError = true;
              return false;
          }
          s -> current = current;
          s -> first = first;
          s -> last = last;
          s -> repeats = repeats;
          s -> next = stack;
       stack = s;
       
       return true;
      }
      /******************************* FUNCTION DEFINITION ******************************
       Name : pop
       Parameters :
        void

       Returns: Void type
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      bool pop ( stackNode *& stack  )
      {
          if ( stack )
          {
              stackNode * temp = stack;
              stack = stack -> next;
              delete temp;
            
              return true;
          }
          return false;
      }
      /******************************* FUNCTION DEFINITION ******************************
       Name : clear
       Parameters :
        void

       Returns: Void type
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      void clear ( stackNode *& stack )
      {
          stackNode * temp;
         
          while ( stack )
          {
              temp = stack;
              stack = stack -> next;
              delete temp;
          }
          stack = 0;
          return;
      }
      /******************************* FUNCTION DEFINITION ******************************
       Name : copy
       Parameters :
        destination a(n) stackNode * ( stackNode * )  ,
        source a(n) stackNode ( stackNode )

       Returns: user defined type , bool
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      bool copy ( stackNode *& destination , stackNode * source )
      {
          int i = 0;
          stackNode * last = 0;
         
          destination = 0;
         
          while ( source )
          {
              stackNode * s = new stackNode;
              if ( ! s )
              {
                  stackError = true;
                  return false;
              }
              if ( i == 0 )
              {
                  destination = s;
                  i ++;
              }
              if ( last )
                  last -> next = s;
             
             
              s -> current = source -> current;
              s -> first = source -> first;
           s -> last = source -> last;
              s -> repeats = source -> repeats;
              s -> next = 0;
              last = s;
              source = source -> next;
       }
       
       return true;
      }
      /******************************* FUNCTION DEFINITION ******************************
       Name : pushState
       Parameters :
        stack a(n) stateNode *& ( stateNode *& )  ,
        frontPattern a(n) stateNode * ( stateNode * )  ,
        currentPattern a(n) stateNode * ( stateNode * )  ,
        currentFrontPattern a(n) stateNode * ( stateNode * )  ,
        currentBackPattern a(n) stateNode * ( stateNode * )  ,
        currentStack a(n) stackNode * ( stackNode * )  ,
        frontStack a(n) stackNode * ( stackNode * )

       Returns: user defined type , bool
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      bool pushState ( stateNode *& stack , fretNode * currentPattern , fretNode * currentFrontPattern , fretNode * currentBackPattern , stackNode * currentStack , stackNode * frontStack )
      {
         
          stateNode * s = new stateNode;
          if ( ! s )
          {
              stackError = true;
              return false;
          }
         
         // s -> fp = frontPattern;
          s -> cp = currentPattern;
          s -> cfp = currentFrontPattern;
          s -> cbp = currentBackPattern;
          copy ( s -> cs , currentStack );
          copy ( s -> fs , frontStack );
          s -> next = stack;
          stack = s;

       return true;
      }
      /******************************* FUNCTION DEFINITION ******************************
       Name : popState
       Parameters :
        stack a(n) stackNode * ( stackNode * )  ,
        frontPattern a(n) stateNode *& ( stateNode *& )  ,
        currentPattern a(n) stateNode *& ( stateNode *& )  ,
        currentFrontPattern a(n) stateNode *& ( stateNode *& )  ,
        currentBackPattern a(n) stateNode *& ( stateNode *& )  ,
        currentStack a(n) stackNode *& ( stackNode *& )  ,
        frontStack a(n) stackNode *& ( stackNode *& )

       Returns: user defined type , bool
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      bool popState ( stateNode *& stack , fretNode *& currentPattern , fretNode *& currentFrontPattern , fretNode *& currentBackPattern , stackNode *& currentStack , stackNode *& frontStack )
      {
          if ( stack == 0 )
          {
              return false;
          }
         
         // frontPattern = stack -> fp;
          currentPattern = stack -> cp;
          currentFrontPattern = stack -> cfp;
          currentBackPattern = stack -> cbp;
          currentStack = stack -> cs;
          frontStack = stack -> fs;
          stack = stack -> next;
         
          return true;
      }
      /******************************* FUNCTION DEFINITION ******************************
       Name : clear
       Parameters :
        void

       Returns: Void type
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      void clear ( stateNode *& stack )
      {
          stateNode * temp;
         
          while ( stack )
          {
              temp = stack;
              stack = stack -> next;
              clear ( temp -> cs );
              clear ( temp -> fs );
              delete temp;
          }
          stack = 0;
          return;
      }
      /******************************* FUNCTION DEFINITION ******************************
       Name : copy
       Parameters :
        destination a(n) stackNode * ( stackNode * )  ,
        source a(n) stackNode ( stackNode )

       Returns: user defined type , bool
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      bool copy ( stateNode *& destination , stateNode * source )
      {
          int i = 0;
          stateNode * last = 0;
         
          destination = 0;
          while ( source )
          {
              stateNode * s = new stateNode;
              if ( ! s )
              {
                  stackError = true;
                  return false;
              }
              if ( i == 0 )
              {
                  destination = s;
                  i ++;
              }
              if ( last )
                  last -> next = s;
             
              //s -> fp = source -> fp;
              s -> cp = source -> cp;
              s -> cfp = source -> cfp;
           s -> cbp = source -> cbp;
              copy ( s -> cs , source -> cs );
              copy ( s -> fs , source -> fs );
              s -> next = 0;
              last = s;
              source = source -> next;
       }
       
       return true;
      }
      /******************************* FUNCTION DEFINITION ******************************
       Name : setState
       Parameters :
        stack a(n) stateNode *& ( stateNode *& )  ,
        currentPattern a(n) fretNode *& ( fretNode *& )  ,
        currentFrontPattern a(n) fretNode *& ( fretNode *& )  ,
        currentBackPattern a(n) fretNode *& ( fretNode *& )  ,
        currentStack a(n) stackNode *& ( stackNode *& )  ,
        frontStack a(n) stackNode *& ( stackNode *& )

       Returns: user defined type , void
       Comments:
       
      ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
      void setState ( stateNode *& stack , fretNode *& currentPattern , fretNode *& currentFrontPattern , fretNode *& currentBackPattern , stackNode *& currentStack , stackNode *& frontStack )
      {
          currentPattern = stack -> cp;
          currentFrontPattern = stack -> cfp;
       currentBackPattern = stack -> cbp;
          currentStack = stack -> cs;
          frontStack = stack -> fs;
       return;
      }
    • #3418
      kanwar
      Participant

      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!

Viewing 5 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.