小编Val*_*s S的帖子

为什么我们在冒泡排序算法中进行n-1次迭代

泡泡排序算法最常见的方法是有两个for循环.内部一个从j = 0到j ni-1完成.我假设我们减去负i,因为当我们到达最后一个元素时,我们不比较它,因为我们之后没有一个元素.但为什么我们使用n-1.为什么我们不从i = 0运行外循环直到i <n并且从j = 0到ni?有人可以向我解释一下,互联网上的教程并没有强调这一点.

for (int i = 0; i < n - 1; i++) // Why do we have n-1 here?
    {
        swapped = false;
        for (int j = 0; j < n - i - 1; j++)
        {
            countComparisons++;
            if (arr[j] > arr[j + 1])
            {
                countSwaps++;
                swap(&arr[j], &arr[j + 1]);
                swapped = true;
            }

        }
     }
Run Code Online (Sandbox Code Playgroud)

例如,如果我有一个包含6个元素的数组,为什么我只需要进行5次迭代?

c++ sorting bubble-sort

1
推荐指数
2
解决办法
1161
查看次数

图标悬停减少过渡

在悬停时我正在使用过渡来增加平滑图标.但问题是,当我将鼠标拖出图标时,它会立即恢复正常大小.我不知道如何通过减少图标来做同样的事情.我的意思是当我将鼠标拖出图标时,它应该转到正常大小并且具有相同的平滑过渡(不是即时).我希望你能理解我.这是我的代码:

li {
  display: inline;
  margin-left: 2.5vh;
	margin-right: 2.5vh;
}

.facebook:hover{
  cursor: pointer;
  transform: scale(0.8);
  transition: all .2s ease-in-out 0s;
  -webkit-transform: all .2s ease-in-out 0s;
}

.instagram:hover{
  cursor: pointer;
  transform: scale(0.8);
  transition: all .2s ease-in-out 0s;
  -webkit-transform: all .2s ease-in-out 0s;
}

.dribble:hover{
  cursor: pointer;
  transform: scale(0.8);
  transition: all .2s ease-in-out 0s;
  -webkit-transform: all .2s ease-in-out 0s;
}

.facebook, .instagram, .dribble {
  transform: scale(0.65);
  -webkit-transform: scale(0.65);
}
Run Code Online (Sandbox Code Playgroud)
<a target="_blank" href="#"><li><img src="http://icons.iconarchive.com/icons/danleech/simple/64/facebook-icon.png" class="facebook"></li></a>
			<a target="_blank" href="#"><li><img src="https://awesomeshop.target.com/img/instagram_logo.png" class="instagram"></li>
			<a target="_blank" href="#"><li><img …
Run Code Online (Sandbox Code Playgroud)

html css transition hover css3

0
推荐指数
1
解决办法
94
查看次数

HTML &amp; CSS 进度条不会停在最后

我已经创建了这个进度条,但我无法让它在最后停止。目前它在 70% 处停止并被清除。有任何想法吗?是否有任何类型的动画设置可以将其停止在 100%?

.wrap {
  background-color: #f2f2f2;
  height: 10px;
  width: 400px;
  margin: 0 auto;
  position: relative;
  top: 20px;
  margin-bottom: 20px;
}

.bar {
  background: #ffcc00;
  height: 10px;
  width: 0%;
}

.animating {
  -webkit-animation: progress 3s ;
}

@-webkit-keyframes progress {
  0% {
    width: 0%;
  }
  100% {
    width: 70%;
  }
}
Run Code Online (Sandbox Code Playgroud)
<div class="wrap">
  <div class="bar animating"></div>
</div>
Run Code Online (Sandbox Code Playgroud)

html css animation

0
推荐指数
1
解决办法
538
查看次数

标签 统计

css ×2

html ×2

animation ×1

bubble-sort ×1

c++ ×1

css3 ×1

hover ×1

sorting ×1

transition ×1