自制阿胶糕怎么做:如何上机实现循环队形?

来源:百度文库 编辑:中科新闻网 时间:2024/04/28 15:17:03
大家快快来帮忙呀,我快要死了!

很简单的啊,可以使用各种链结构来实现,我给你单链表的实现方法:
1.构建1个简单的单链表:
typedef struct _list
{
int i4_node;
struct _list* p_next;
}LIST,*PLIST;

PLIST plist;//这个就是我们要的链表了~
2.构建加入节点函数,由于是循环的,所以你需要给出加在哪里:
void addNode(int local)
{
PLIST tempnode;
PLIST pos=plist;
int count=0;
tempnode = malloc(sizeof(LIST));//这里是新加入的节点;
if(pos->next==NULL) //空链或只有1个节点
{
pos->next=tempnode;
return;
}
for(;count<local;count++)
{
if(pos->next==NULL)
{
pos=plist; //循环到尾回到头
}
}
//找到插入点开始插入
tempnode->next=post->next;
post->next=tempnode;
}

3.删除,和2基本上一摸一样,都是先找到位置再删除,不过多了个free删除过的节点的操作