Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- class node{
- public:
- int value;
- node *ptr;
- };
- node list;
- node empty;
- node empty2;
- void CreateList(node &head){
- head.value = -1;
- head.ptr = NULL;
- }
- void AddEntry(node &head, int value){
- static node ThisNode;
- head.value += 1;
- if(head.value == 0){
- head.ptr = new node;
- head.ptr->value = value;
- return;
- }else{
- ThisNode = head;
- for(int i = 0; i < head.value; ++i){
- ThisNode = *(ThisNode.ptr);
- }
- ThisNode.ptr = new node;
- ThisNode.ptr->value = value;
- ThisNode.ptr->ptr = NULL;
- return;
- }
- }
- node GetEntry(node head, int entry){
- static node ThisNode;
- ThisNode = head;
- for(int i = 0; i <= entry; ++i){
- ThisNode = *(ThisNode.ptr);
- }
- return ThisNode;
- }
- int main(){
- CreateList(list);
- AddEntry(list, 6); //0
- empty = GetEntry(list, 0);
- printf("%d\n", empty.value);
- AddEntry(list, 4); //1
- empty2 = GetEntry(list, 1);
- printf("%d\n", empty2.value);
- //printf("%d\n", list.value);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement