6 Replies - 495 Views - Last Post: 05 June 2012 - 03:17 AM Rate Topic: -----

#1 bigbig  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 12-March 12

Move elements from cyclic linked list to double linked list as dequeue

Posted 04 June 2012 - 09:35 AM

Hello everyone, i have done cyclic linked list and double linked list as dequeue.But after all i have to move all elements cyclic list to deqeueu.How i can do that? I should not copy just move
PLEASE HELP PEOPLE :helpsmilie: :helpsmilie:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

struct sar
{
       int elem;
       struct sar *kitas;
       };
       
 struct dek{
       int duom;
       struct dek *kitas;
       struct dek *pries ;
       };
 //---------------------------------------------------------------------------//      
      struct sar *iskirti_vietos()
       {
           struct sar *naujas;
       naujas =(sar *) malloc(sizeof(struct sar));
       naujas->kitas = NULL;
       return (naujas);
       }
//----------------------------------------------------------------------------//       
       struct sar *sukurti()
       {
              char t;
              int tuscias=1;
              struct sar *pradzia,*naujas,*laikin;
              struct sar *iskirti_vietos();
              do
              {
                     naujas=iskirti_vietos();
                     printf("\n\n\n\tIveskite elementa\n");
                     scanf("%d",&naujas->elem);
                     if(tuscias==1)
                     {
                                  pradzia= naujas;
                                  naujas->kitas=pradzia;
                                  tuscias=0;
                                  }
              else
              {
                  laikin=pradzia; 
                  while(laikin->kitas!=pradzia)
                  laikin= laikin->kitas;
                  laikin->kitas= naujas;
                  naujas->kitas=pradzia;
                  }
                  printf("\n Ar norite ivesti dar elementus?[T/N]\n");
                  t=getch();
                  }while(t=='T'||t=='t');
                  return pradzia;
                  }
//----------------------------------------------------------------------------//                  
          void spausdinimas(struct sar *pradzia)
                  { struct sar *laikin;
                  laikin=pradzia;
                  if(laikin==NULL)
                  printf("Sarasas yra tuscias, iterpkite elementus\n");
                  else 
                  {
                       do
                       {
                             printf("%d\t",laikin->elem);
                             laikin=laikin->kitas;
                             }while (laikin!=pradzia);
                             }
                             getch();
                             }
//----------------------------------------------------------------------------//
    struct sar *ieskoti (sar *pradzia,int n)
    {
           struct sar *laikin;
           laikin=pradzia;
           while(laikin->kitas != pradzia)
                {
                               if(laikin->elem==n)
                               {
                               return laikin;
                               printf("Elementas surastas: %d",n);
                               }
                               else 
                              laikin=laikin->kitas; 
                               }
                               return NULL;
                               }
//----------------------------------------------------------------------------//
   struct sar *istrinti (struct sar *pradzia)
        {
              int k;
              struct sar *laikin,*laikin1;
              printf("\n Iveskite elementa kuri norite istrinti");
              scanf("%d",&k);
              laikin=pradzia;
              if (laikin->elem==k)
              {
                               laikin1=laikin->kitas;
                               if (laikin1==laikin)
                               {
                                                   laikin=NULL;
                                                   pradzia=laikin;
                                              printf("\n Elementas Istrintas");
                                                   }
                                                   else
                                                   {
                               while(laikin->kitas!=pradzia)
                               laikin=laikin->kitas;
                               laikin->kitas=laikin1;
                               pradzia=laikin1;
                               printf("\n Elementas Istrintas");
                               }
                               }
                               else 
                               {
                                    while(laikin->kitas!=pradzia)
                                    {
                                    if((laikin->kitas)->elem==k)
                                    {
                                    laikin1=laikin->kitas;
                                    laikin->kitas=laikin1->kitas;
                                    laikin1->kitas=NULL;
                                    free(laikin1);
                                    printf("\n Elementas Istrintas");
                                    }
                                    laikin=laikin->kitas;
                                    }
                                    }
                                    return pradzia;
                                    }
//----------------------------------------------------------------------------//

   void deko_sukurimas(struct dek * *pr, struct dek * *pab)
 {
    *pr = NULL;
    *pab = NULL;
}     
//----------------------------------------------------------------------------//

  void el_iterpimas_pradzia(struct dek * *pr, struct dek * *pab,int sk_1)
 {
     struct dek *g;
     int x,i;

	 if ( *pr == NULL)
	    {
	      g = (struct dek *) malloc(sizeof(struct dek));
	      g -> duom =sk_1;
	      g -> kitas = NULL;
	      g -> pries = NULL;
	      *pr = g;
	      *pab =g;
	    }
	 else
	    {
	      g = (struct dek *) malloc(sizeof(struct dek));
	      g -> duom = sk_1;
	      
	      g -> kitas = *pr;
	      (*pr) -> pries = g;
	      g -> pries = NULL;
	      *pr = g;
	    }
       }                     
//----------------------------------------------------------------------------//

void naikinimas_pradzioje(struct dek * *pr, struct dek * *pab)
 {
   struct dek *g;
   if (*pr == NULL)
      {
	printf("Dekas yra tuscias.\n");
	getch();
    return;
    }
   
   g = *pr;
   if ( g -> kitas != NULL)
      {
	printf("Panaikintas elemntas %d is deko pradzios.\n", g -> duom);
	g = g -> kitas;
	g -> pries = NULL;
	free ( *pr );
	*pr = g;
      }
   else
      {
	printf("Panaikintas elemntas %d is deko pradzios.\n", g -> duom);
	free ( *pr );
	*pr = NULL;
	*pab = NULL;
      }
    getch();
 }
 
//----------------------------------------------------------------------------//

 void el_iterpimas_pabaiga(struct dek * *pr, struct dek * *pab, int sk_1)
 {
   struct dek *g;
   int x, i, s;
if (*pr == NULL)
	   {
	     g = (struct dek *) malloc(sizeof(struct dek));
	     g -> duom = sk_1;
	     g -> kitas = NULL;
	     g -> pries = NULL;
	     *pr = g;
	     *pab = g;
	   }
	else
	   {
	     g = (struct dek *) malloc(sizeof(struct dek));
	     g -> duom = sk_1;
	     g -> kitas = NULL;
	     g -> pries = *pab;
	     (*pab) -> kitas = g;
	     *pab = g;
	   }
 }
 
//----------------------------------------------------------------------------//

void naikinimas_pabaigoje(struct dek * *pr, struct dek * *pab)
  {
    struct dek *g;
   if (*pab == NULL)
      {
	printf("Dekas yra tuscias.\n");
	getch();
    return;
      } 
      
       g = *pab;
   if ( g -> pries != NULL)
      {
	printf("Panaikintas elemntas %d is deko pabaigos.\n", g -> duom);
	g = g -> pries;
	g -> kitas = NULL;
	free ( *pab );
	*pab = g;
      }
   else
      {
	printf("Panaikintas elemntas %d is deko pabaigos.\n", g -> duom);
	free ( *pab );
	*pr = NULL;
	*pab = NULL;
      }
    getch();
}

//----------------------------------------------------------------------------//
   void el_ziurejimas(struct dek  *pr )
 { 
    if ( pr == NULL)
       printf("Dekas tuscias.\n");
    else
       while (pr != NULL)
	  {
             
	    printf("%d\n", pr -> duom);
	    pr = pr -> kitas;
	  }
    getch();
 }

/*struct sar *p(struct dek * *pr,struct dek * *pab,struct sar *pradzia,int sk_1)
{
    struct dek *pradz, *pabaiga;
     struct  sar *laikin;
    pradz=0;
    pabaiga=0;
    char z;
                  laikin=pradzia;
                 // printf("%d\n",laikin);
                  if(laikin==NULL)
                  printf("Sarasas yra tuscias, iterpkite elementus\n");
                  else 
                  { 
  deko_sukurimas(&pradz, &pabaiga);
                       do
                     { 
    printf ("Pasirinkite kur noresite iterpti elementus P-pradzia,B-pabaiga\n");
     scanf("%c,&z") ;
     if ((z=='P')||(z=='p'))
     {
              sk_1=laikin->elem;
                el_iterpimas_pradzia(&pradz, &pabaiga, sk_1);
                             laikin=laikin->kitas; 
                               el_ziurejimas(pradz);
                             }               
     else if ((z=='B')||(z=='b'))
     {
         sk_1=laikin->elem;
          el_iterpimas_pabaiga(&pradz, &pabaiga, sk_1);
          laikin=laikin->kitas;
           el_ziurejimas(pradz);
         
      }

     
     
     
                             }while (laikin!=pradzia);
                             }
                             getch();
                             }
*/



                             
                             
                          
                        int  main()
                           {
                                struct sar *pradzia, *laikin;
                                struct dek *pradz, *pabaiga;
                                 deko_sukurimas(&pradz, &pabaiga);
                                
                                char ch;
                               int k,pasirinkimas,s,tt;
                              pradzia=NULL;
                                do
                                {
                                         system("CLS");
                                          printf("1.-Iterpti elementus\n");
                                          printf("2.-Atspausdinti elementus\n");
                                          printf("3.-Surasti   elementus\n");
                                          printf("4.-Istrinti  elementus\n");
                              printf("5.-Perkelti  elementus i deko pradzia\n");
                        printf("6.-Istrinti elementus is galo ar pradzios\n");
                           printf("7.-Perziureti  elementus is deko\n");
                                          printf("8.-Iseiti is programos\n");
                                        printf("\n\n-Iveskite pasirinkima- : ");
                                      
                                          scanf("%d",&pasirinkimas);
                                          switch(pasirinkimas)
                                          {
                                             case 1:
                                                  pradzia=sukurti();
                                                  break;
                                             case 2:
                                                  spausdinimas(pradzia);
                                                  break;
                                             case 3:
                                          printf("\n\nKoki elementa surasti?");
                                          scanf("%d",&k);
                                          laikin=ieskoti(pradzia,k);
                                          break;
                                                  
                                             case 4:
                                                  pradzia=istrinti(pradzia);
                                                  break;
                                              case 5:
                                        //  p(&pradz,&pabaiga,pradzia,tt);
                                        el_iterpimas_pradzia(&pradz,&pabaiga,tt);                                        
                                     break;
                                     case 6: 
                                          
                                          break;
                                     case 7:
                        el_ziurejimas(pradz);
                                          break;
                                     
                                     case 8:
                                                  exit(0);
                                                  
                                     default: 
                                     printf("SIO MENIU PUNKTO NERA!!\n");   
                                     return 0;         
                                                  
                                                  }
                                      system("CLS");             
                             printf("Ar norite dar pasirinkti is meniu?[T/N]");
                                                  ch=getch();
                                                  } while (ch=='T'||ch=='t');
                                                  }
                                                  
                                          
                                          



Is This A Good Question/Topic? 0
  • +

Replies To: Move elements from cyclic linked list to double linked list as dequeue

#2 Salem_c  Icon User is online

  • void main'ers are DOOMED
  • member icon

Reputation: 1624
  • View blog
  • Posts: 3,082
  • Joined: 30-May 10

Re: Move elements from cyclic linked list to double linked list as dequeue

Posted 04 June 2012 - 10:14 AM

Your indentation is just awful.
http://sourceforge.n...tle=Indentation

Few will bother with the necessary effort to get your code into an editor just so they can reformat it for readability.
Was This Post Helpful? 0
  • +
  • -

#3 bigbig  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 12-March 12

Re: Move elements from cyclic linked list to double linked list as dequeue

Posted 04 June 2012 - 10:21 AM

:dozingoff: but i think if i even correct them you dont help me coz you not interesting to help.
Was This Post Helpful? 0
  • +
  • -

#4 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • Joined: 08-January 12

Re: Move elements from cyclic linked list to double linked list as dequeue

Posted 04 June 2012 - 10:53 AM

Well, as Salem_c said, after reading your poorly formatted code and poor grammar, most people like me will skip past this topic..
Was This Post Helpful? 0
  • +
  • -

#5 bigbig  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 12-March 12

Re: Move elements from cyclic linked list to double linked list as dequeue

Posted 04 June 2012 - 11:12 AM

okey nevermind thank you
Was This Post Helpful? 0
  • +
  • -

#6 #define  Icon User is online

  • Duke of Err
  • member icon

Reputation: 1307
  • View blog
  • Posts: 4,497
  • Joined: 19-February 09

Re: Move elements from cyclic linked list to double linked list as dequeue

Posted 04 June 2012 - 07:19 PM

View Postbigbig, on 04 June 2012 - 07:35 PM, said:

Hello everyone, i have done cyclic linked list and double linked list as dequeue.But after all i have to move all elements cyclic list to deqeueu.How i can do that? I should not copy just move
PLEASE HELP PEOPLE :helpsmilie: :helpsmilie:



Could your cyclic linked list also be double linked?
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3463
  • View blog
  • Posts: 10,669
  • Joined: 05-May 12

Re: Move elements from cyclic linked list to double linked list as dequeue

Posted 05 June 2012 - 03:17 AM

View Postbigbig, on 04 June 2012 - 10:21 AM, said:

:dozingoff: but i think if i even correct them you dont help me coz you not interesting to help.


Guilt tripping people into helping you is not an effective strategy either.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1