void main()
{
	THTREE H=NULL, S=NULL, R=NULL;
	create_a_node(H, ' ');
	H->rtag=TRUE;
	H->ltag=FALSE;
	H->lchild=H;
	H->rchild=H;
	
	create_a_node(S, 'a');
	LInsert(H, S);
	create_a_node(R, 'c');
	RInsert(S, R);
	create_a_node(R, 'b');
	LInsert(S, R);
	create_a_node(S, 'd');
	LInsert(R, S);
	create_a_node(S, 'e');
	RInsert(R, S);
	create_a_node(R, 'f');
	RInsert(S, R);

	ThInOrder(H);
	cout<<endl;
}
Beispiel #2
0
// Add edges 
void AddEdge(ALGraph* pg, int fromV, int toV)
{
	// Add vertex 'toV' into the list of v
	LInsert(&(pg->adjList[fromV]), toV);
	LInsert(&(pg->adjList[toV]), fromV);

	pg->numOfEdge++;
}
int main(void)
{
	// List의 생성 및 초기화  ////////////
	List list;
	int data;
	ListInit(&list);

	SetSortRule(&list, WhoIsPrecede);

	// 5개의 데이터 저장  ///////////////
	LInsert(&list, 11);  LInsert(&list, 11);
	LInsert(&list, 22);  LInsert(&list, 22);
	LInsert(&list, 33);

	// 저장된 데이터의 전체 출력 ////////////
	printf("현재 데이터의 수: %d \n", LCount(&list));

	if(LFirst(&list, &data))
	{
		printf("%d ", data);
		
		while(LNext(&list, &data)) 
			printf("%d ", data);
	}
	printf("\n\n");

	// 숫자 22을 검색하여 모두 삭제 ////////////
	if(LFirst(&list, &data))
	{
		if(data == 22)
			LRemove(&list);
		
		while(LNext(&list, &data))
		{
			if(data == 22)
				LRemove(&list);
		}
	}

	// 삭제 후 저장된 데이터 전체 출력 ////////////
	printf("현재 데이터의 수: %d \n", LCount(&list));

	if(LFirst(&list, &data))
	{
		printf("%d ", data);
		
		while(LNext(&list, &data))
			printf("%d ", data);
	}
	printf("\n\n");
	return 0;
}
int main(void)
{
	// 양방향 연결 리스트의 생성 및 초기화  ///////
	List list;
	int data;
	ListInit(&list);

	// 8개의 데이터 저장  ///////
	LInsert(&list, 1);  LInsert(&list, 2);
	LInsert(&list, 3);  LInsert(&list, 4);
	LInsert(&list, 5);  LInsert(&list, 6);
	LInsert(&list, 7);  LInsert(&list, 8);

	// 저장된 데이터의 조회  ///////
	if(LFirst(&list, &data))
	{
		printf("%d ", data);

		while(LNext(&list, &data)) 
			printf("%d ", data);
		
		while(LPrevious(&list, &data))
			printf("%d ", data);
		
		printf("\n\n");
	}

	return 0;
}
Beispiel #5
0
int main(void){
	//ArrayList Create and Init
	List list;
	int data;
	ListInit(&list);

	LInsert(&list, 11);LInsert(&list, 11);
	LInsert(&list, 22);LInsert(&list, 22);
	LInsert(&list, 33);

	//Saved data print
	printf("Present Data Count : %d\n",LCount(&list));

	if(LFirst(&list, &data)){
		printf("%d ", data);

		while(LNext(&list, &data)){
			printf("%d ", data);
		}
	}
	printf("\n\n");

	// Search 22 and Delete
	if(LFirst(&list, &data)){
		if(data == 22)
			LRemove(&list);

		while(LNext(&list, &data)){
			if(data == 22)
				LRemove(&list);
		}
	}

	//Presend Data Count
	printf("Present Data Count: %d\n",LCount(&list));

	if(LFirst(&list, &data)){
		printf("%d ", data);

		while(LNext(&list, &data)){
			printf("%d ", data);
		}
	}
	printf("\n\n");
	return 0;
}
Beispiel #6
0
int main(){
	List list;
	int data;
	ListInit(&list);

	LInsert(&list, 11);LInsert(&list, 11);
	LInsert(&list, 22);LInsert(&list, 22);
	LInsert(&list, 33);

	printf("Present Data Count : %d\n", LCount(&list));

	if(LFirst(&list, &data)){
		printf("%d ", data);

		while(LNext(&list, &data))
			printf("%d ", data);
	}
	printf("\n\n");

	if(LFirst(&list, &data)){
		if(data == 22)
			LRemove(&list);

		while(LNext(&list, &data)){
			if(data == 22)
				LRemove(&list);
		}
	}

	printf("Present Data Count : %d\n",LCount(&list));

	if(LFirst(&list, &data)){
		printf("%d ", data);

		while(LNext(&list, &data))
			printf("%d ", data);
	}
	printf("\n\n");
	return 0;
}
Beispiel #7
0
void AddEdge(ALGraph * pg, int fromV, int toV)
{
	LInsert(&(pg->adjList[fromV]), toV);
	LInsert(&(pg->adjList[toV]), fromV);
	pg->numE ++;
}
int main(void)
{
	List list;
	Point comPos; // 비교할 좌표값
	Point * ppos;

	ListInit(&list);

	//4개의 데이터 저장 
	ppos = (Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 2, 1);
	LInsert(&list, ppos);

	ppos = (Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 2, 2);
	LInsert(&list, ppos);

	ppos = (Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 3, 1);
	LInsert(&list, ppos);

	ppos = (Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 3, 2);
	LInsert(&list, ppos);


	// 저장된 데이터 출력
	printf("현재 데이터의 수 : %d\n", LCount(&list));
	if(LFirst(&list, & ppos))
	{
		ShowPointpos(ppos);

		while(LNext(&list, &ppos))
			ShowPointpos(ppos);
	}
	printf("\n");
	// xpos가 (2 , 0)인 데이터는 모두 삭제를 하자 

	comPos.xpos =2;
	comPos.ypos = 0;

	if(LFirst(&list, &ppos))
	{
		if(PointComp(ppos, &comPos) == 1)
		{
			ppos = LRemove(&list);
			free(ppos);
		}

		while(LNext(&list, &ppos))
		{
			if(PointComp(ppos, &comPos) ==1)
			{
				ppos = LRemove(&list);
				free(ppos);
			}
		}


	}

	// 삭제를 하고 남아있는 데이터 수 
	printf("현재 데이터의 수 : %d\n", LCount(&list));
	if(LFirst(&list, & ppos))
	{
		ShowPointpos(ppos);

		while(LNext(&list, &ppos))
			ShowPointpos(ppos);
	}
	printf("\n");

	return 0;
}
Beispiel #9
0
int main(){
	List list;
	NameCard* pcard;
	NameCard chPhone;

	ListInit(&list);

	pcard = MakeNameCard("Phantom", "010-1111-2222");
	LInsert(&list, pcard);

	pcard = MakeNameCard("HeadFish", "010-2222-3333");
	LInsert(&list, pcard);

	pcard = MakeNameCard("Mathboy", "010-3333-4444");
	LInsert(&list, pcard);

	printf("Present Data Count : %d\n", LCount(&list));

	if(LFirst(&list, &pcard)){
		ShowNameCardInfo(pcard);

		while(LNext(&list, &pcard))
			ShowNameCardInfo(pcard);
	}

	printf("\n\n");

	strcpy(chPhone.name, "Mathboy");
	strcpy(chPhone.phone, "010-3333-4444");

	if(LFirst(&list, &pcard)){
		if(NameCompare(pcard, "Mathboy")==1){
			ChangePhoneNum(pcard, "010-7777-8888");
		}

		while(LNext(&list, &pcard)){
			if(NameCompare(pcard, "Mathboy")==1){
				ChangePhoneNum(pcard, "010-7777-8888");
			}
		}
	}

	printf("Present Data Count : %d\n", LCount(&list));

	if(LFirst(&list, &pcard)){
		ShowNameCardInfo(pcard);

		while(LNext(&list, &pcard))
			ShowNameCardInfo(pcard);
	}

	printf("\n\n");

	if(LFirst(&list, &pcard)){
		if(NameCompare(pcard, "Mathboy")==1){
			pcard = LRemove(&list);
			free(pcard);
		}

		while(LNext(&list, &pcard)){
			if(NameCompare(pcard, "Mathboy")==1){
				pcard = LRemove(&list);
				free(pcard);
			}
		}
	}
	if(LFirst(&list, &pcard)){
		ShowNameCardInfo(pcard);

		while(LNext(&list, &pcard))
			ShowNameCardInfo(pcard);
	}

	printf("\n\n");
	printf("Present Data Count : %d\n", LCount(&list));

	return 0;
}
Beispiel #10
0
int main(){
	List list;
	Point compPos;
	Point *ppos;

	ListInit(&list);

	ppos=(Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 2, 1);
	LInsert(&list,ppos);

	ppos=(Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 2, 2);
	LInsert(&list,ppos);

	ppos=(Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 3, 1);
	LInsert(&list,ppos);

	ppos=(Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 3, 2);
	LInsert(&list,ppos);

	printf("Present Data Count : %d\n",LCount(&list));

	if(LFirst(&list,&ppos)){
		ShowPointPos(ppos);

		while(LNext(&list,&ppos))
			ShowPointPos(ppos);
	}
	printf("\n");

	compPos.xpos=2;
	compPos.ypos=0;


	if(LFirst(&list,&ppos)){
		if(PointComp(ppos, &compPos)==1){
			ppos=LRemove(&list);
			free(ppos);
		}
		while(LNext(&list,&ppos)){
			if(PointComp(ppos, &compPos)==1){
				ppos=LRemove(&list);
				free(ppos);
			}
		}
	}

	printf("Present Data Count : %d\n",LCount(&list));


	if(LFirst(&list,&ppos)){
		ShowPointPos(ppos);

		while(LNext(&list,&ppos))
			ShowPointPos(ppos);
	}
	printf("\n");
	return 0;
}
Beispiel #11
0
int main(void)
{
  // ArrayList 의 생성 및 초기화
  List list;
  int data;
  ListInit(&list);

  // 5개의 데이터 저장
  LInsert(&list, 11);
  LInsert(&list, 11);
  LInsert(&list, 22);
  LInsert(&list, 22);
  LInsert(&list, 33);

  // 저장된 데이터의 전체 출력
  printf("현재 데이터의 수:%d \n", LCount(&list));

  if (LFirst(&list, &data)) // 첫 번째 데이터 조회
  {
    printf("%d ", data);

    while(LNext(&list, &data))  // 두 번째 이후의 데이터 조회
    {
      printf("%d ", data);
    }
  }

  printf("\n\n");

  // 숫자 22를 탐색하여 모두 삭제
  if (LFirst(&list, &data))
  {
    if (data == 22)
    {
      LRemove(&list);
    }
    while (LNext(&list, &data))
    {
      if (data == 22)
      {
        LRemove(&list);
      }
    }
  }

  // 삭제 후 남은 데이터 전체 출력
  printf("현재 데이터의 수: %d \n", LCount(&list));

  if (LFirst(&list, &data))
  {
    printf("%d ", data);

    while (LNext(&list, &data))
    {
      printf("%d ", data);
    }
  }

  printf("\n\n");
  return 0;
}
int main(void)
{
	List list;
	Point compPos;
	Point * ppos;

	ListInit(&list);

	/*** 4개의 데이터 저장 ***/
	ppos = (Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 2, 1);
	LInsert(&list, ppos);

	ppos = (Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 2, 2);
	LInsert(&list, ppos);

	ppos = (Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 3, 1);
	LInsert(&list, ppos);

	ppos = (Point*)malloc(sizeof(Point));
	SetPointPos(ppos, 3, 2);
	LInsert(&list, ppos);

	/*** 저장된 데이터의 출력 ***/
	printf("현재 데이터의 수: %d \n", LCount(&list));

	if(LFirst(&list, &ppos))
	{
		ShowPointPos(ppos);
		
		while(LNext(&list, &ppos))
			ShowPointPos(ppos);
	}
	printf("\n");

	/*** xpos가 2인 모든 데이터 삭제 ***/
	compPos.xpos=2;
	compPos.ypos=0;

	if(LFirst(&list, &ppos))
	{
		if(PointComp(ppos, &compPos)==1)
		{
			ppos=LRemove(&list);
			free(ppos);
		}
		
		while(LNext(&list, &ppos)) 
		{
			if(PointComp(ppos, &compPos)==1)
			{
				ppos=LRemove(&list);
				free(ppos);
			}
		}
	}

	/*** 삭제 후 남은 데이터 전체 출력 ***/
	printf("현재 데이터의 수: %d \n", LCount(&list));

	if(LFirst(&list, &ppos))
	{
		ShowPointPos(ppos);
		
		while(LNext(&list, &ppos))
			ShowPointPos(ppos);
	}
	printf("\n");

	return 0;
}
Beispiel #13
0
int main()
{
	List list;
	NameCard *newCard;
	int i;
	ListInit(&list);

	//1. 3명의 전화번호 정보를, 앞서 우리가 구현한 리스트에 저장한다.
	newCard = MakeNameCard("조현일","01065429759");
	LInsert(&list,newCard);
	newCard = MakeNameCard("김민서","01044450324");
	LInsert(&list,newCard);
	newCard = MakeNameCard("김태윤","01088350650");
	LInsert(&list,newCard);

	
	//2. 특정 이름을 대상으로 탐색을 진행하여, 그 사람의 정보를 출력한다.
	puts("=======[조현일]을 대상으로 탐색=======\n");

	if(LFirst(&list,&newCard)){
		if(!NameCompare(newCard,"조현일"))
			ShowNameCardInfo(newCard);
		while(LNext(&list,&newCard))
			if(!NameCompare(newCard,"조현일"))
				ShowNameCardInfo(newCard);
	}

	//3. 특정 이름을 대상으로 탐색을 진행하여, 그 사람의 전화번호 정보를 변경한다.

	puts("=======[김태윤]를 대상으로 탐색=======\n");

	if(LFirst(&list,&newCard)){
		if(!NameCompare(newCard,"김태윤"))
			ChangePhone(newCard,"01044449999");
		while(LNext(&list,&newCard))
			if(!NameCompare(newCard,"김태윤"))
				ChangePhone(newCard,"01044449999");

		puts("전화번호를 01044449999로 변경완료!\n");
	}


	//4. 특정 이름을 대상으로 탐색을 진행하여, 그 사람의 정보를 삭제한다.

	puts("=======[김민서]를 대상으로 탐색=======\n");

	if(LFirst(&list,&newCard)){
		if(!NameCompare(newCard,"김민서"))
			LRemove(&list);
		while(LNext(&list,&newCard))
			if(!NameCompare(newCard,"김민서"))
				LRemove(&list);

		puts("데이터 삭제완료!\n");
	}
	
	//5. 끝으로 남아있는 모든 사람의 전화번호 정보를 출력한다.

	puts("---남아있는 모든 사람의 전화번호 출력----\n");
	
	if(LFirst(&list,&newCard)){
		ShowNameCardInfo(newCard);

		while(LNext(&list,&newCard))
		ShowNameCardInfo(newCard);
	}

	return 0;
}