/* list.h - */
/* Copyright 2018-2028 zyyt, Inc. */
/*
modification history
--------------------
modification history
--------------------
01a 19jan18 zj added this head
*/
/*
DESCRIPTION
DESCRIPTION
NULL.
*/
#ifndef __list_H__
#define __list_H__
*/
#ifndef __list_H__
#define __list_H__
#include "PDAtype.h"
#ifdef __cplusplus
extern "C" {
#endif
extern "C" {
#endif
/*
typedef struct //structCard
{
int CardNum; //short int CardNum;
short int Count;
// unsigned char BatAlarm;
// unsigned char Emergency;
union
{
struct
{
unsigned int BatAlarm : 1; //LSB
unsigned int Emergency : 1;
unsigned int : 1;
unsigned int : 1; // CTCSSMode
typedef struct //structCard
{
int CardNum; //short int CardNum;
short int Count;
// unsigned char BatAlarm;
// unsigned char Emergency;
union
{
struct
{
unsigned int BatAlarm : 1; //LSB
unsigned int Emergency : 1;
unsigned int : 1;
unsigned int : 1; // CTCSSMode
unsigned int : 1; //MSB
} Bits;
unsigned int StausValue;
} CardStaus;
//char VehicleNum[10];
}TCard;
*/
#define MAX_LIST_LEN 300
typedef struct //structCard
{
int length; //
TCard arrayCard[MAX_LIST_LEN];
*/
#define MAX_LIST_LEN 300
typedef struct //structCard
{
int length; //
TCard arrayCard[MAX_LIST_LEN];
}TCardList;
TCard listNodeAt(int index);
TCard listGetMin();
TCard listGetMax();
TCard listGetMin();
TCard listGetMax();
#ifdef __cplusplus
}
#endif
}
#endif
#endif
/* list.c - */
/* Copyright 2018-2028 zyyt, Inc. */
/*
modification history
--------------------
modification history
--------------------
01a 19jan18 zj added this head
*/
/*
DESCRIPTION
DESCRIPTION
NULL.
*/
#include "PDAtype.h"
#include "list.h"
#include <stdio.h>
*/
#include "PDAtype.h"
#include "list.h"
#include <stdio.h>
TCardList cardList;
void listInit()
{
int i;
cardList.length = 0;
for (i = 0; i < MAX_LIST_LEN; i++) {
cardList.arrayCard[i].CardNum = 0;
cardList.arrayCard[i].Count = 0;
cardList.arrayCard[i].CardStaus.StausValue = 0;
}
}
cardList.arrayCard[i].Count = 0;
cardList.arrayCard[i].CardStaus.StausValue = 0;
}
}
void listAdd(TCard card)
{
if(cardList.length>=MAX_LIST_LEN){
cardList.length=0;
}
cardList.arrayCard[cardList.length++] = card;
}
int listIndexOf(TCard card)
{
int i;
for (i = 0; i < cardList.length; i++) {
{
int i;
for (i = 0; i < cardList.length; i++) {
if (cardList.arrayCard[i].CardNum == card.CardNum)
{
return i;
}
}
return -1;
}
{
return i;
}
}
return -1;
}
void listInsert(int index, TCard card)
{
int i;
for (i = cardList.length - 1; i > index - 1; i--) {
cardList.arrayCard[i + 1] = cardList.arrayCard[i];
{
int i;
for (i = cardList.length - 1; i > index - 1; i--) {
cardList.arrayCard[i + 1] = cardList.arrayCard[i];
}
cardList.arrayCard[index] = card;
cardList.length++;
}
cardList.arrayCard[index] = card;
cardList.length++;
}
void listUpdate(int index, TCard card)
{
{
if (index < cardList.length) {
cardList.arrayCard[index] = card;
}
}
cardList.arrayCard[index] = card;
}
}
TCard listNodeAt(int index)
{
return cardList.arrayCard[index];
{
return cardList.arrayCard[index];
}
TCard listGetMax()
{
int i;
TCard cardMax;
{
int i;
TCard cardMax;
cardMax = cardList.arrayCard[0];
for (i = 1; i < cardList.length; i++) {
if (cardList.arrayCard[i].CardNum > cardMax.CardNum)
{
cardMax = cardList.arrayCard[i];
}
}
return cardMax;
{
cardMax = cardList.arrayCard[i];
}
}
return cardMax;
}
TCard listGetMin()
{
int i;
TCard cardMin;
{
int i;
TCard cardMin;
cardMin = cardList.arrayCard[0];
for (i = 1; i < cardList.length; i++) {
if (cardList.arrayCard[i].CardNum < cardMin.CardNum)
{
cardMin = cardList.arrayCard[i];
}
}
return cardMin;
}
{
cardMin = cardList.arrayCard[i];
}
}
return cardMin;
}
int listLength()
{
{
return cardList.length;
}
void listRemove(TCard card)
{
int indexOfRm;
int i;
{
int indexOfRm;
int i;
indexOfRm = listIndexOf(card);
if (indexOfRm > 0) {
for (i = indexOfRm + 1; i < cardList.length; i++) {
cardList.arrayCard[i - 1] = cardList.arrayCard[i];
for (i = indexOfRm + 1; i < cardList.length; i++) {
cardList.arrayCard[i - 1] = cardList.arrayCard[i];
}
cardList.length--;
}
cardList.length--;
}
}
void listRemoveAll()
{
listInit();
{
listInit();
}
void listPrint()
{
int i;
printf("cardList.length %d\r\n", cardList.length);
for (i = 0; i < cardList.length; i++)
{
printf("[%d]%d ", i, cardList.arrayCard[i].CardNum);
}
printf("\r\n");
}
void listMake()
{
TCard card;
int i;
TCard card;
int i;
card.CardNum = 3;
listRemoveAll();
for (i = 0; i < 30; i++)
{
card.CardNum = 1+i;
card.Count = 5;
card.CardStaus.Bits.BatAlarm = 1;
listAdd(card);
}
listRemoveAll();
for (i = 0; i < 30; i++)
{
card.CardNum = 1+i;
card.Count = 5;
card.CardStaus.Bits.BatAlarm = 1;
listAdd(card);
}
listPrint();
}
void listTest()
{
TCard card1, card2, card3;
TCard card4, card5, card6;
card1.CardNum = 3;
card2.CardNum = 7;
card3.CardNum = 8;
card2.CardNum = 7;
card3.CardNum = 8;
card4.CardNum = 71;
card5.CardNum = 82;
card6.CardNum = 85;
card5.CardNum = 82;
card6.CardNum = 85;
listAdd(card1);
listPrint();
listAdd(card2);
listAdd(card3);
listPrint();
listAdd(card3);
listPrint();
listRemove(card2);
listPrint();
listInsert(1, card4);
listPrint();
listPrint();
listAdd(card5);
listAdd(card6);
listPrint();
printf("listIndexOf %d %d\r\n",card5.CardNum,listIndexOf(card5));
listRemoveAll();
listPrint();
listAdd(card6);
listPrint();
listAdd(card6);
listPrint();
printf("listIndexOf %d %d\r\n",card5.CardNum,listIndexOf(card5));
listRemoveAll();
listPrint();
listAdd(card6);
listPrint();
}