// linked list gba.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
enum EKEYSTATE
{
a,
b,
c,
d,
e
};
//BUFFER FOR CURRENT KEYS
//Purpose: to store information about the keys in the current buffer
struct SKey_buffer
{
volatileunsignedchar vuc_KEYSTATE;
SKey_buffer * next;
bool bHead;
};
SKey_buffer _buff6;
SKey_buffer _buff5;
SKey_buffer _buff4;
SKey_buffer _buff3;
SKey_buffer _buff2;
SKey_buffer _buff1;
SKey_buffer* iter;//iter head
SKey_buffer * iter_Head;//temp storage for iter head
SKey_buffer* iter_newNULL; //initialised to current null
void BUFFER_keysinit();
void BUFFER_newKeys(volatileunsignedchar a);
int _tmain(int argc, _TCHAR* argv[])
{
BUFFER_keysinit();
volatileunsignedchar a = 'A';
int i = 0;
while (i < 200)
{
BUFFER_newKeys(a);
a++;
std::cout<<iter->vuc_KEYSTATE<<std::endl;
i++;
}
return 0;
}
//initialise key input buffer
void BUFFER_keysinit()
{
_buff6.next = NULL; _buff6.bHead = false;
_buff5.next = &_buff6; _buff5.bHead = false;
_buff4.next = &_buff5; _buff4.bHead = false;
_buff3.next = &_buff4; _buff3.bHead = false;
_buff2.next = &_buff3; _buff2.bHead = false;
_buff1.next = &_buff2; _buff1.bHead = true;
iter_Head = &_buff1;//head at initialisation
iter = iter_Head; //head at start of traversing
iter_newNULL = &_buff6; //initialised to current null
}
void BUFFER_newKeys(volatileunsignedchar a)
{
///////////////////////////////////////////////////////////////////////////////
//section continuously executed
//Locate current NULL
for (iter;iter->next != NULL;iter = iter->next)
{
//This will be the last iterrator prior the last,
//NULL with wont be executed
iter_newNULL->next = iter;
}
//iter == null
if (iter->next == NULL)
{
//current NULL, = current state
iter->vuc_KEYSTATE = a;
//current NULL iter = New head
//point to old head: set old head to false
iter_Head->bHead = false;
iter->next = iter_Head;
iter->bHead = true;
//NEW iter_head = "current NULL"
iter_Head = iter;
//active new null to null
iter_newNULL->next = NULL;
}
///////////////////////////////////////////////////////////////////////////////
}
// linked list gba.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
enum EKEYSTATE
{
a,
b,
c,
d,
e
};
//BUFFER FOR CURRENT KEYS
//Purpose: to store information about the keys in the current buffer
struct SKey_buffer
{
volatileunsignedchar vuc_KEYSTATE;
SKey_buffer * next;
bool bHead;
};
SKey_buffer _buff6;
SKey_buffer _buff5;
SKey_buffer _buff4;
SKey_buffer _buff3;
SKey_buffer _buff2;
SKey_buffer _buff1;
SKey_buffer* iter;//iter head
SKey_buffer * iter_Head;//temp storage for iter head
SKey_buffer* iter_newNULL; //initialised to current null
void BUFFER_keysinit();
void BUFFER_newKeys(volatileunsignedchar a);
int _tmain(int argc, _TCHAR* argv[])
{
BUFFER_keysinit();
volatileunsignedchar a = 'A';
int i = 0;
while (i < 200)
{
BUFFER_newKeys(a);
a++;
std::cout<<iter->vuc_KEYSTATE<<std::endl;
i++;
}
return 0;
}
//initialise key input buffer
void BUFFER_keysinit()
{
_buff6.next = NULL; _buff6.bHead = false;
_buff5.next = &_buff6; _buff5.bHead = false;
_buff4.next = &_buff5; _buff4.bHead = false;
_buff3.next = &_buff4; _buff3.bHead = false;
_buff2.next = &_buff3; _buff2.bHead = false;
_buff1.next = &_buff2; _buff1.bHead = true;
iter_Head = &_buff1;//head at initialisation
iter = iter_Head; //head at start of traversing
iter_newNULL = &_buff6; //initialised to current null
}
void BUFFER_newKeys(volatileunsignedchar a)
{
///////////////////////////////////////////////////////////////////////////////
//section continuously executed
//Locate current NULL
while (iter->next != NULL)
{
//This will be the last iterrator prior the last,
//NULL with wont be executed
iter_newNULL->next = iter;
iter = iter->next;
}
//iter == null
if (iter->next == NULL)
{
//current NULL, = current state
iter->vuc_KEYSTATE = a;
//current NULL iter = New head
//point to old head: set old head to false
iter_Head->bHead = false;
iter->next = iter_Head;
iter->bHead = true;
//NEW iter_head = "current NULL"
iter_Head = iter;
//active new null to null
iter_newNULL->next = NULL;
}
///////////////////////////////////////////////////////////////////////////////
}