Results 1 to 5 of 5

Thread: How to reverse the order of the letters using linked list?

  1. #1
    Join Date
    Dec 2009
    Posts
    42

    How to reverse the order of the letters using linked list?

    Hello to all,
    I am last year Computer Science student. I recently started learning c-language. In our last lecture we got assignment on c-language. In that assignment one program is there like write a program to reverse the order of the letters using linked list? I tried various method but none of the worked out. Can anyone help me to get solution of it.
    Thank you.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to reverse the order of the letters using linked list?

    Hey it is very easy program to reverse the order of the letters using linked list. I have written following code for you. In the following code I have use iostream class to include all input and output method. I also have use one array variable to accept all string.
    Code:
    #include <iostream>
    using namespace std;
    int main(){
        char as[9] = {'a','b','c','d','e','f','g','h','i'};
        
        for (int k=1;k<=9;k++){
            as[k-1];
            }
            cout<<"the output in reverse order  \n";
            for (int k=8;k>=0;k--)
            cout<<as[k]<<endl;
            char cs;
            cin>>cs;
            }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How to reverse the order of the letters using linked list?

    As per my knowledge following is the most simple and very advanced program to reverse the order of the letters using linked list. Just try to understand this simple program. In the following code I have use iostream class to include all input and output method. I have use class named as "linklisteg" to include all methods.

    Code:
    #include <iostream>
    using namespace std;
    
    class linklisteg
    {
         private:
                 struct nodes
                 {
                        char datass;
                        node *link;
                 }*ps;
       public:
              linklisteg();
              void append( int nums );
              void display();
              void print(nodes*& heads);
              ~linklisteg();
    };
    
    linklisteg::linklisteg()
    {
         ps=NULL;
    }
    
    void linklisteg::append(int nums)
    {
         node *qs,*ts;
    
       if( ps == NULL )
       {
          ps = new nodes;
          ps->data = nums;
          ps->link = NULLs;
       }
       else
       {
          qs = ps;
          while( qs->links != NULLs )
          qs = qs->links;
    
          ts = new nodes;
          ts->datas = num;
          ts->links = NULL;
          qs->links = ts;
       }
    }
    
    void linklist::display()
    {
         node *qs;
         cout<<endl;
    
       for( qs = ps ; qs != NULL ; qs = qs->link )
            cout<<endl<<qs->data;
    
    }
    
    void print(nodes*& heads)
    {
         nodes * temps = heads;
         if (temps->nexst != null)
         {
              print(temps->next);
         }
              cout << temps->bases; }
              
    linklist::~linklist()
    {
         node *q;
       if( p == NULL )
            return;
    
       while( ps != NULL )
       {
            qs = ps->links;
          delete ps;
          ps = qs;
       }
    }
    
    int main()
    {
         linklist ll;
       ll.append('as');
       ll.append('bs');
       ll.append('cs');
       ll.append('ds');
       ll.append('es');
       ll.append('sg');
       ll.append('sh');
       ll.append('is');
       ll.display();
       cout<<"\n\n\n";
    
    
    
       system("pause");
       return 0;
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to reverse the order of the letters using linked list?

    I have written following code for you. It is very simple program. In the following code I have use ReverseList( ) function to reverse the order of the letters using linked list. I also have use while loop to do this. Just try to understand each line carefully.
    Code:
    Node* ReverseList( Node ** List )	
    {
    
    	Node *temps1 = *List;
    	Node * temps2 = NULL;
    	Node * temps3 = NULL;
    
    	while ( temps1 )
    	{
    		*List = temps1; 	
    temps2= temps1->pNext; 
    		temps1->pNext = temps3;
    		temps3 = temps1;
    		temps1 = temps2;
    	}
     
    	return *List;
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to reverse the order of the letters using linked list?

    Just go through following program.
    Code:
    Void ReverseList(node* head)
    {
        node *temps,*currents,*resulst;
        temps=null;
        results=null;
        currents=head;
        while(currents!=null)
        {
            temps=currents->next;
            currents->next=results;
            results=currents;
            currents=temps;
        }
       head=results;
    I have written following program to reverse the order of the letters using linked list. It is very simple program. In this code I have use ReverseList(node* head) function to reverse the word.

Similar Threads

  1. Need help to reverse the name order in Microsoft Excel
    By Kesar in forum MS Office Support
    Replies: 3
    Last Post: 24-01-2012, 02:16 PM
  2. How to Reverse Row Order in Microsoft Excel
    By Raju Chacha in forum MS Office Support
    Replies: 1
    Last Post: 14-01-2012, 06:25 PM
  3. How to reverse Page Order in Acrobat Pro 9
    By Patricia-USA in forum Windows Software
    Replies: 5
    Last Post: 13-07-2010, 06:38 AM
  4. How can I reverse the order of text on a Excel cell
    By Sunny55 in forum Windows Software
    Replies: 3
    Last Post: 06-06-2009, 09:50 PM
  5. How to reverse print order in Word 2007??
    By NavinS in forum MS Office Support
    Replies: 1
    Last Post: 23-01-2008, 12:47 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,715,184,002.70220 seconds with 17 queries