[c++] list with head node
来源:互联网 发布:java获取tomcat根目录 编辑:程序博客网 时间:2024/05/17 13:11
/* * g++ ListTest.cpp -o L * valgrind ./L */#include <stdio.h>#include <stdlib.h>struct ListNode{ListNode* pNext;int Value;};class IntList{public:IntList() throw(){m_Front.pNext=NULL;m_Front.Value=-1;m_pRear = &m_Front;}~IntList() throw(){ListNode *p = m_Front.pNext;while(p!=NULL){m_Front.pNext=p->pNext;free(p);p=m_Front.pNext;}}bool Empty() const throw() {return m_Front.pNext==NULL;}void Push(int v) throw(){ListNode *p = (ListNode*) malloc(sizeof(ListNode));if(p!=NULL){p->pNext=NULL;p->Value=v;m_pRear->pNext=p;m_pRear=p;}}int Front() const throw(){if(m_Front.pNext!=NULL) return m_Front.pNext->Value;else return -1;}int Rear() const throw(){return m_pRear->Value;}void Pop() throw(){ListNode *p=m_Front.pNext;if(p!=NULL){m_Front.pNext=p->pNext;free(p);if(m_Front.pNext==NULL) m_pRear=&m_Front;}}private:ListNode m_Front;ListNode* m_pRear;};int main(){IntList int_list;int index=0;for(int i=0;i<100;++i) int_list.Push(i);while(int_list.Empty()==false){if(int_list.Front()!=index){printf("Error, index=%d,Front()=%d",index,int_list.Front());}printf("value = %d\n",int_list.Front());index = int_list.Front()+1;int_list.Pop();}for(int i=0;i<100;++i) int_list.Push(i);return 0;}
0 0
- [c++] list with head node
- 1006. insert for single link list with head node
- 1007. remove for single link list with head node
- The Link List with C
- C++: delete a node from linked list
- 【LeetCode with Python】 Remove Nth Node From End of List
- Realize the linear list with C
- List node
- head item alv LIST
- [C++]LeetCode: 4 Remove Nth Node From End of List
- [leetcode-237]Delete Node in a Linked List(C语言)
- [leetcode-]Remove Nth Node From End of List(C)
- [C语言][LeetCode][237]Delete Node in a Linked List
- LeetCode 237. Delete Node in a Linked List C语言
- LeetCode之Delete Node in a Linked List (Java+C)
- 【LeetCode-19】Remove Nth Node From End of List(C++)
- Leetcode Linked List Random Node C++(蓄水池抽样算法)
- LeetCode 382. Linked List Random Node 题解(C++)
- codeforces 730J (01背包)
- HDU2099
- poj-2186-Popular Cows (tarjan算法)
- spring mvc inteceptor 拦截器实现计算controller 的执行时间
- 1+2!+3!+…+20!(求 20!20的阶乘)
- [c++] list with head node
- HDU2277 找规律 变球的颜色
- javac命令使用教程
- 校验class文件的魔数,前四个字节
- 113.将音频转化为MP3格式(lame库)
- HDU2500 水题 打印
- LeetCode No.403 Frog Jump
- HDU2501 骨牌 水题 找规律
- cocos2dx ios平台发布&&发布广告