示例#1
0
void clearhead(headtyp *hp)
/* Eliminerar alla länkar från listan */
{
   linktyp *ep;

   while ( !empty(hp) )
   {
      ep = firstlink(hp);
      elimlink(&ep);
   }
}
示例#2
0
int nrlinks(headtyp *hp)
/* Returnerar antalet länkar i listan */
{
   int sum = 0;
   linktyp *ep;

   ep = firstlink(hp);
   while ( ep != NULL )
   {
      sum++;
      ep = succlink(ep);
   }
   return sum;
}
struct listnode *insertnode(struct listnode *head,int *address,int t)
{
	 int info,i,x,y,count=0,position;
	 struct listnode *p,*temp;
	 char ch[50];

		if(head==0)
		{
			getdata(300,400,0,"            LIST IS EMPTY");
			return head;
		}

		info=getdata(300,400,2,"ENTER A NUM(2 DIGI)0 EXIT");

	for(count=0,p=head;p!=0;p=p->next,count++);

	sprintf(ch,"ENTER POSITION(1 TO %d)",count+1);
	position=getdata(300,400,2,ch);


	if(position<=0||position>12||count+1<position)
	{
		getdata(300,400,0,"          INVALID POSITION ");
		return head;
	}

     if(count>=12)
     {
	  getdata(300,400,0,"CAN'T TAKE MORE THAN 12 NODES");
	  return head;
     }

	temp=(struct listnode*)calloc(sizeof(struct listnode),1);

	if(temp==0)
	{
	   getdata(100,100,0,"Memory not avilable,con't create node");
	   return head;
	}

	temp->pre=0;
	temp->next=0;
	temp->num=info;
	temp->add=*address;

	*address+=50;
	temp->padd=0;
	temp->nadd=0;

 if(position==1)
   {
opmessage( 160, 400, ' ',"Put Link New Node to Head Node And Set Head Is New Node",MAGENTA);
		drawnode(160,150,temp,t);
		firstlink();
		sleep(1);
opmessage( 160, 400, ' ',"Put Link New Node to Head Node And Set Head Is New Node",BLACK);

		temp->next=head;
		head->pre=temp;
		head->padd=temp->add;
		temp->nadd=head->add;
		head=temp;

		display(head,t);
		return head;

   }

     for( i=2,p=head;i<position&&p->next!=0;i++,p=p->next);

     if(count+1==position)
	{
 opmessage( 160, 400, ' ',"Create New Node And Put Link Last Node to New Node ",MAGENTA);
	 sleep(1);
 opmessage( 160, 400, ' ',"Create New Node And Put Link Last Node to New Node ",BLACK);

		p->next=temp;
		temp->pre=p;
		temp->padd=p->add;
		p->nadd=temp->add;

		display(head,t);

		return head;
	}

   sprintf(ch,"Create New Node And Put Link New Node to  %d Node ",position);
   opmessage( 160, 400, ' ',ch,MAGENTA);
   sprintf(ch," And Put Link  %d Node To New Node ",position-1);
   opmessage( 160, 410, ' ',ch,MAGENTA);
   delay(1000);

			temp->next=p->next;
			p->next->pre=temp;
			temp->nadd=p->next->add;
			p->next->padd=temp->add;
			temp->pre=p;
			temp->padd=p->add;
			p->next=temp;
			p->nadd=temp->add;

		if(position==5||position==9)
		{
			if(position==5)
			y=150;
			else
			y=250;

		  x=520;
		  newlink(x,y-50,1);
		  drawnode(x,y,temp,t);
		  rlinelink(x,y);
		  sleep(1);
		  llinelink(x,y-50);

			sleep(1);
   sprintf(ch,"Create New Node And Put Link New Node to  %d Node ",position);
	   opmessage( 160, 400, ' ',ch,BLACK);
   sprintf(ch," And Put Link  %d Node To New Node ",position-1);
	   opmessage( 160, 410, ' ',ch,BLACK);

			display(head,t);

			return head;
		}

				if(position>1&&position<5)
					y=100;
				if(position>5&&position<9)
					y=200;
				if(position>9&&position<12)
					y=300;

				if(position==2||position==6||position==10)
					x=160;
				if(position==3||position==7||position==11)
					x=280;
				if(position==4||position==8)
					x=400;

		drawnode(x+60,y+50,temp,t);
		nlink(x,y,1);
		rlink(x+120,y);
		sleep(1);

		llink(x,y);

		sleep(1);
   sprintf(ch,"Create New Node And Put Link New Node to  %d Node ",position);
		opmessage( 160, 400, ' ',ch,BLACK);
   sprintf(ch," And Put Link  %d Node To New Node ",position-1);
		opmessage( 160, 410, ' ',ch,BLACK);

		display(head,t);

	   return head;

}
示例#4
0
void Store( pwr_tBoolean *firstTime, pwr_tUInt32 *nrOfEvents, pwr_tUInt32 *nrOfKeys )
{
  char msg[80];
  pwr_tInt32 ret = 0;

  DBT key;
  sKey skey;

  /*flush the cache to the DB-file*/
  dataBaseP->sync(dataBaseP, 0);
  
  /*check if it's time to clean the DB*/
  if( *firstTime || ((*nrOfEvents + nrOfInsertsSinceLastTime) > lHelCB.MaxCardinality ) )
  {
    *firstTime = FALSE;
    if(nrOfInsertsSinceLastTime > 0)
    {
      nrOfInsertsSinceLastTime--;
      *nrOfEvents = *nrOfEvents + 1;
    }
    if( *nrOfKeys <= 0)
    {
      ret = GetOldestEvents(nrOfEvents, nrOfKeys);
      nrOfInsertsSinceLastTime = 0;
      switch(ret)
      {
        case RT_ELOG_UNKNOWN_ERROR:
          errh_Error("RT_ELOG_UNKNOWN_ERROR");
          break;
        case RT_ELOG_OK:
          break;
        case RT_ELOG_DB_EMPTY:
          break;
        default:
          errh_Error("Undefined return: %d", ret);
          break;
      }
    }
    else
    {      
      lanklank = firstlink(listhead);
      skey = getlink(lanklank);
      memset(&key, 0, sizeof(key));
      key.data = &skey;
      key.size = sizeof(sKey);

      if( (ret = dataBaseP->del(dataBaseP, NULL, &key, 0)) != 0 )
      {
        sprintf(msg, "Error deleting Record in HistDB nrOfKeys = %d Errmess=%s\n", *nrOfKeys, db_strerror(ret));
	Log(msg);
      }
      else
      {
        *nrOfEvents = *nrOfEvents - 1;
      }
      
      elimlink(&lanklank);
      *nrOfKeys = *nrOfKeys - 1;
    }
      
  }
  if(*nrOfKeys > 0)
  {
      lanklank = firstlink(listhead);
      if(lanklank != 0)
      {
        writeInfo(*nrOfEvents+nrOfInsertsSinceLastTime, 0, &lanklank->data.EventTime);
      }
      else
      {
        writeInfo(*nrOfEvents+nrOfInsertsSinceLastTime, 0, NULL);
      }
  }
  else
  {
    writeInfo(*nrOfEvents+nrOfInsertsSinceLastTime, 0, NULL);
  }
}