Exemple #1
0
void Combine(SLList *L1, SLList *L2, int commond) /* commond: 1表示相加, 2表示相减 */
{
	SLList *L = NULL;
	SLInit(&L);
	SLList *head = L1;
	while (head->next != NULL)
	{
		head = head->next;
		SLAppend(L, head->tag, head->object, head->size);
	}
	head = L2;

	while (head->next != NULL)
	{
		head = head->next;
		SLList *find = SLWalk(L, Find, head->object);
		if (find == NULL) /* 链表中没有此项 */
		{
			SLList *insertPos = SLWalk(L, FindInsertPosition, head->object);
			if (insertPos == NULL) /* 挂在链尾 */
			{
				SLAppend(L, head->tag, head->object, head->size);
			}
			else  /* instet before insertPos */
			{
				SLAdd(SLGetPri(L, insertPos), head->tag, head->object, head->size);
			}
		}
		else  /*链表中已存在此项 */
		{
			Term *oldTerm = find->object;
			Term *newTerm = head->object;
			if (commond == 1)
			{
				oldTerm->c += newTerm->c;
			}
			else if (commond == 2)
			{
				oldTerm->c -= newTerm->c;
			}

			if (oldTerm->c == 0)
			{
				SLDeleteNext(SLGetPri(L, find));
			}
			else
			{
				SLUpdate(L, 0, oldTerm, sizeof(Term));
			}
		}
	}
	SLWalk(L, PrintItem, NULL);
	SLDestory(L);
}
Exemple #2
0
void main()
{
	int i;
	SLType SL;
	DATA data;
	DATA *pdata;

		printf("顺序表操作演示!\n");
		SLInit(&SL);
		printf("初始化顺序表完成!\n");

		do{
			printf("输入添加的节点(学号 姓名 年龄):");
			fflush(stdin);
			scanf("%s %s %d",&data.key,&data.name,&data.age);
			if(data.age)
			{
				if(!SLAdd(&SL,data))
				{
					break;
				}
			}
			else
			{
				break;
			}
		}while(1);

		printf("\n顺序表中的结点顺序为:\n");
		SLAll(&SL);

		fflush(stdin);
		printf("\n要取出节点的序号:");
		scanf("%d",&i);
		pdata = SLFindByNum(&SL,i);
		if(pdata)
		{
			printf("第%d个结点为:(%s,%s,%d)\n",i,pdata->key,pdata->name,pdata->age);
		}


}
Exemple #3
0
/*
** Put a name on the network and return the file descriptor.
** This is called by read_conf().
*/
void add_name(int prnid)
	{
	static int appletalk_started = FALSE;
	int fd;						/* server endpoint file descriptor */
	int err;
	const char *name;

	if( ! appletalk_started )	/* Since add_name() will be the first */
		{						/* function in this module to be called, */
		DODEBUG_STARTUP(("initializing appletalk"));
		abInit(FALSE);			/* we will use it to initialize the AppleTalk. */
		nbpInit();
		PAPInit();
		appletalk_started = TRUE;
		strcpy(status.StatusStr, "xThe PPR spooler is starting up.");
		status.StatusStr[0] = (unsigned char)strlen(&status.StatusStr[1]);
		}

	name = adv[prnid].PAPname;

	debug("registering name: %s", name);

	while((err = SLInit(&fd, name, MY_QUANTUM, &status)) != 0)
		{
		if(err == nbpNoConfirm)
			{
			debug("Name registration failed");
			sleep(1);
			debug("Retry...");
			}
		if(err==nbpDuplicate)
			fatal(1, "Name \"%s\" already exists", name);
		else
			fatal(1, "SLInit() failed, err=%d",err);
		}

	adv[prnid].fd = fd;
	endpoints[prnid].fd = fd;	/* Remember the file descriptor. */
	} /* add_name() */